Earlier I asked why this is considered bad:
class Example { public: Example(void); ~Example(void); void f() {} } int main(void) { Example ex(); // <<<<<< what is it called to call it like this? return(0); }
Now, I understand that it’s creating a function prototype instead that returns a type Example. I still don’t get why it would work in g++ and MS VC++ though.
My next question is using the above, would this call be valid?
int main(void) { Example *e = new Example(); return(0); }
? What is the difference between that and simply calling Example e()??? Like I know it’s a function prototype, but it appears maybe some compilers forgive that and allow it to call the default constructor? I tried this too:
class Example { private: Example(); public: ~Example(); }; int main(void) { Example e1(); // this works Example *e1 = new Example(); // this doesn't return(0); }
So I’m a bit confused 🙁 Sorry if this been asked a million times.
this question will be helpful to understand this behavior