RAD Studio
ContentsIndex
PreviousUpNext
E2251: Cannot find default constructor to initialize base class 'class'

Whenever a C++ derived class 'class2' is constructed, each base class 'class1' must first be constructed. 

If the constructor for 'class2' does not specify a constructor for 'class1' (as part of 'class2's' header), there must be a constructor class1::class1() for the base class. 

This constructor without parameters is called the default constructor. 

The compiler will supply a default constructor automatically unless you have defined any constructor for class 'class1'. 

In that case, the compiler will not supply the default constructor automatically--you must supply one.

class Base {
public:
   Base(int) {}
};
class Derived = public Base {
   Derived():Base(1) {}
}
// must explicitly call the Base constructor, or provide a
// default constructor in Base.

Class members with constructors must be initialized in the class' initializer list, for example:

class A {
public
   A( int );
};
class B {
public:
   A a;
   B() : a( 3 ) {}; //ok
};
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!