Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

constructor is in implementation file or main program file?

OpenStudy (anonymous):

The definition, or the invokation of the constructor?

OpenStudy (anonymous):

I'd like to take a guess, constructor implementation is in the main program file. :p

OpenStudy (anonymous):

Right; you have a header file, like myclass.h, with the class definition and all the constructors and destructors and method prototypes and definitions. // Myclass.h class Myclass { Myclass(); ~Myclass(); // More stuff }; Then you have a separate file implementing those constructors and destructors etc. // Myclass.cpp Myclass::Myclass() { // ctor } Myclass::~Myclass() { // dtor } // More stuff

OpenStudy (anonymous):

You don't typically have either defined in the same file as the main function. Instead, you would include Myclass.h if you want to use Myclass objects. #include "Myclass.h" int main() { Myclass myobject; // etc. }

OpenStudy (anonymous):

sorry I forgot to put `public:' before the constructors and destructors :-P

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!