In computer science a constructor is a method called when an instance of a class is created, after the memory has been allocated. A constructor can also be used to refer to a tag to create an abstract data type in the Haskell programming language.

Table of contents
1 Example
2 Also see

Example

C++

class Foo
{
   // This is the prototype of the constructor
   Foo(int X);
}

Foo::Foo(int X) {

   // This is the implementation of the constructor
}

int main() {

   // This is where the constructor is being called
   Foo* foo = new Foo(14);

delete Foo;

return 0;

}

Also see

Destructor (antonym).