#include<iostream> #include<cstdlib> using namespace std; class Simple{ public: Simple(){ cout << "I'm a constructor!" << endl; } }; int main() { cout << "Case 1 : "; Simple * sp1 = new Simple; cout << "Case 2 : "; Simple*sp2 = (Simple*)malloc(sizeof(Simple) * 1); cout << endl << "end of main" << endl; delete sp1; free(sp2); return 0; }
#include<iostream> using namespace std; int& RefRetFuncOne(int &ref)//참조자. 별명 { ref++; return ref; } int main(void){ int num1 = 1; int &num2 = RefRetFuncOne(num1); num1++; num2++; cout << "num1 : " << num1 << endl; cout << "num2 : " << num2 << endl; return 0; }
#include<iostream> using namespace std; int& RefRetFuncOne(int &ref)//참조자. 별명 { ref++; return ref; } int main(void){ int num1 = 1; int num2 = RefRetFuncOne(num1); num1+=1; num2+=100; cout << "num1 : " << num1 << endl; cout << "num2 : " << num2 << endl; return 0; }
#include<iostream> using namespace std; int RefRetFuncOne(int &ref)//참조자. 별명 { ref++; return ref; } int main(void){ int num1 = 1; int num2 = RefRetFuncOne(num1); num1+=1; num2+=100; cout << "num1 : " << num1 << endl; cout << "num2 : " << num2 << endl; return 0; }