RAD Studio |  |

E2352: Cannot create instance of abstract class 'class' (C++)

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:

Copy Code

    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:

Copy Code

    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) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!