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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -