c++ - Why can I declare constructor out of the class -
consider link. see code:
class myclass { public: myclass(); ~myclass(); private: int _a; }; myclass::myclass() { } myclass::~myclass() { }
we can declare constructor out of class.
why can declare constructor out of class , why should this?
you cannot declare constructor out of class. talking constructor definition.
class myclass { public: myclass(); // declaration }; myclass::myclass() // definition { }
you should read this.
the main reason why should define constructor outside class readability. clearer declare class in header file , define in source file. can apply rule members of class.
a little quote standard :
12.1 constructors
struct s { s(); // declares constructor }; s::s() { } // defines constructor
Comments
Post a Comment