Constructors (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, or const volatile.

You do not specify a return type for a constructor. A return statement in the body of a constructor cannot have a return value.

Related information