Another academic inquiry - what is the protected / private code purpose / function in this class generated by ATmel STudio
-
class M { //variables public: protected: private: //functions public: M(); ~M(); virtual int foo(int); protected: private: M( const M &c ); M& operator=( const M &c ); int i, j; }; //M Thanks, any help as always is appreciated. Cheers Vaclav
-
class M { //variables public: protected: private: //functions public: M(); ~M(); virtual int foo(int); protected: private: M( const M &c ); M& operator=( const M &c ); int i, j; }; //M Thanks, any help as always is appreciated. Cheers Vaclav
If your question is, why the copy constructor and assignment operator are declared private: This is to prevent the users of the class from copying objects of that type. At least the assignment operator is created atomatically by the compiler, if the designer of the class doesn't explicitely specify one. This default assignment operator simply copies all members. So without the operator you could write
M m1, m2;
m2 = m1;and it would compile. With this class definition as it is, you will get a compile time error that the operator is not accessible.
The good thing about pessimism is, that you are always either right or pleasently surprised.