[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
memory » ASP » eclipseIDE » CPU » CppTemplateMetaprogramming » Os400StrPgmMnu » Os400ChgOwn » TCPIP » CppUtilityH » cppint » CppConstructor
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
memory » ASP » eclipseIDE » CPU » CppTemplateMetaprogramming » Os400StrPgmMnu » Os400ChgOwn » TCPIP » CppUtilityH » cppint » CppConstructor
(C++) Constructor
The method called when a class is instanciated. A class can have multiple constructors.
class Example
{
public:
Example() //Constructor #1
{
mValue = 0;
}
Example(const int& value) //Constructor #2
: mValue(value);
{
//Empty, as mValue is already set to value
}
int mValue;
};
int main(int argc, char* argv[])
{
Example e1; //Calls constructor #1
Example e2(10); //Calls constructor #2
Example * pe1 = new Example; //Calls constructor #1
Example * pe2 = new Example(10); //Calls constructor #2
delete pe1; //Calls destructor
delete pe2; //Calls destructor
}
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
