Abstract class type not allowed as a type for parameter

Submit New Article

Last Modified On :   June 15, 2009 12:02 AM PDT
Rate
 



Problem : 
I encounter an error when compiling "parameter of abstract class type "type" is not allowed", as described in http://software.intel.com/en-us/articles/cdiag646/. Does anybody know why and how to fix it?

Environment : 
Windows, Linux, Mac and Intel C++ compiler.


Resolution : 


The problem is you are trying to declare a parameter that has the type of an abstract base class.

Abstract classes are designed to be only interfaces to real classes because they have one or
more pure virtual functions, i.e.:
class abstract {
virtual void foo() = 0; // pure virtual function since it is declared with = 0
};
void foo(abstract); // not allowed since the class is abstract

The workaround would be to only use pointers or references to the abstract class as parameters, or change the type to a non-abstract class that is derived from the abstract class or change the class so it is no longer abstract, i.e. define the virtual functions instead of declaring them pure virtual.





This article applies to: Intel C++ Compiler and Performance Library for QNX* Neutrino* RTOS Knowledge Base,   Intel® C++ Compiler for Linux* Knowledge Base,   Intel® C++ Compiler for Mac OS X* Knowledge Base,   Intel® C++ Compiler for Windows* Knowledge Base,   Intel® Parallel Composer Knowledge Base