RAD Studio
ContentsIndex
PreviousUpNext
E2352: Cannot create instance of abstract class 'class'

Abstract classes (those with pure virtual functions) can't be used directly, only derived from. 

When you derive an abstract base class, with the intention to instantiate instances of this derived class, you must override each of the pure virtual functions of the base class exactly as they are declared. 

For example:

class A {
public:
   virtual myex( int ) = 0;
   virtual twoex( const int ) const = 0;
};
class B : public A {
public:
   myex( int );
   twoex( const int );
};
B b;   // error

The error occurs because we have not overridden the virtual function in which twoex can act on const objects of the class. We have created a new one which acts on non-const objects. This would compile:

class A {
public:
   virtual myex( int ) = 0;
   virtual twoex( const int ) const = 0;
};
class B : public A {
public:
   myex( int );
   twoex( const int ) const;
};
B b;   // ok
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!