parameter of abstract type

I'm constructing a class MTArray2D with the followin code
HEADER
...
virtual double operator|(MTArray2D other) const = 0;
virtual double inner_product_with(MTArray2D other) const;
...

IMPLEMENTATION
...
double MTArray2D::inner_product_with(MTArray2D other) const
{
return *this | other;
}

Compiler complains that "parameter of abstract class type "MTArray2D" is not allowed:". I'm not sure if I understood this message: I can't use abstract class parameters at all ? If not, why is it complaining? thanx in advance...
Last edited on
You are passing an MTArray2D by value to operator|. This means the compiler must generate a copy of the actual parameter on the stack. However since MTArray2D is an abstract base class (ostensibly) the compiler is complaining that it cannot instantiate an abstract class (because of the copy).

The correct way to declare the function is with a const reference parameter:

 
virtual double operator|( const MTArray2D& other ) = 0;


However, having said that, it is very unusual to declare an operator virtual because operators and inheritance although workable are awkward.

Topic archived. No new replies allowed.