Ok, here i have 2 simple C++ examples, the first one is:
MyClass
class MyClass
{
private:
int test;
public:
int member(){
test = 456;
return 1;
} // one public function
};
global function definition
int funct(MyClass** obj)
{
*obj = new MyClass();
int c = (**obj).member();
return 1;
}
main
...
MyClass* object;
int i = funct(&object);
...
while in the second case, i modify the main like this:
MyClass** object = (MyClass **)malloc(sizeof(MyClass));
int i = fun(object);
Both examples work fine, but i'm not sure if i understood correctly why ONLY in this second case i need a malloc (otherwise it wouldn't compile at all).
Thanks in advance for your help
PS: i know double pointers are more C-style programming, but i'm currently experimenting with both languages.