본문 바로가기

카테고리 없음

struct and new, delete operator

#include "stdafx.h"

#include <iostream>

#include <string>


struct MyStruct {

int num1 = 1;

int num2 = 2;

double real1 = 0.5;

};


int main()

{

using namespace std;


const MyStruct *ptr = 0;


ptr = new MyStruct;


cout << ptr->num1 << " " << ptr->num2 << " " << ptr->real1 << endl;


delete ptr;


return 0;

}