Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
Jun 11, 1999

What is the Role of an Implicitly-Declared Constructor?

If there is no user-declared constructor in a class, and the class does not contain const or reference data members, the implementation implicitly declares a default constructor for it. An implicitly-declared default constructor is an inline public member of its class. It performs the initialization operations that are needed by the implementation to create an object instance. Note, however, that these operations do not involve initialization of user-declared data members or allocation of memory from the free store. For example:

 
class C
{
private:
  int n;
  char *p;
public:
  virtual ~C() {}
};

void f()
{
  C obj;  // 1 implicitly-defined constructor is invoked
}

The programmer did not declare a constructor in class C. Therefore, an implicit default constructor was declared and defined by the implementation in order to create an instance of class C. The synthesized constructor does not initialize the data members n and p, nor does it allocate memory for the latter. These data members have an indeterminate value after obj has been constructed.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date