C++ - What is this doing if the constructor is private? -
in code below, why compiler not complain mclass2?
class cmyclass{ private:     cmyclass(){} };  void testmethod(){     cmyclass mclass1;   //fails.     cmyclass mclass2(); //works. }      
because you've declared function mclass2 of 0 arguments returns cmyclass. that's valid option since there be, say, static cmyclass instance function has access to. note cmyclass still has public copy constructor.
(to convince yourself, compile module assembler , observe commenting out line cmyclass mclass2(); produces same output.)
Comments
Post a Comment