soxarered
soxarered

Reputation: 163

Virtual templates?

I am trying to declare an abstract class, but just the act of templating a virtual function makes the compiler complain. How is this normally accomplished? For example, in my header file I have:

virtual SpecialList<Point> *getPoints() const;

To which the compiler states "ISO C++ forbids declaration of 'SpecialList' with no type."

edit Both Point and SpecialList are included in the definition of this class. As a more verbose example,

// SomeClass.h
#include "SpecialList.h"
#include "Point.h"

class SomeClass
{
public:
    SomeClass();
    virtual SpecialList<Point> *getPoints() const;
//snip
};

Still not solved..

Upvotes: 1

Views: 306

Answers (3)

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361352

It looks like you haven't defined Point before you're using it.

Define Point before the abstract class, or include the header file in which it's defined!

--

Or in case if you're trying to define virtual function template, something like this:

template<typename Point>
virtual SpecialList<Point> *getPoints() const;

Then it's not possible. virtual function template is not allowed!

Upvotes: 3

GogaRieger
GogaRieger

Reputation: 345

Check if you #included SpecialList and Point class declarations or forward-declarated or typedefed it.

Upvotes: 0

Yakov Galka
Yakov Galka

Reputation: 72469

struct A
{
    virtual vector<int>* f() const = 0;
};

Works fine for me. Make sure that 'SpecialList' and 'Point' are defined before you use them.

Upvotes: 5

Related Questions