Login    New User    Forgot Password    Help      

Constructors

GO TO INDEX

CConstructors (C++ only)

A constructor is a member function with the same name as its class. For example: class X { public: X(); // constructor for class X }; Constructors are used to create, and can initialize, objects of their class type. You cannot declare a constructor as virtual or static, nor can you declare a constructor as const, volatile, orconst volatile.

Example

class String
{

public:

String() //constructor with no arguments
    :str(NULL),
    size(0)
{

}

String(int size) //constructor with one argument
    :str(NULL),
    size(size)

{
    str = new char[size];
}



private:

    char *str;

    int size;

}

GO TO INDEX