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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -