abstract baseclass, polymorphismn

Hi guys,

i am playing a little bit with polymorphic design and pure virtual methods.

i have a abstract base class as follow:

1
2
3
4
5
6
7
  class CCodec
{
public:
	virtual void write(ostream &stream, const vector<CWaypoint> &waypoints, const vector<CPOI*> &pois)  = 0;
	virtual void read(vector<CWaypoint> &waypoints, vector <CPOI> &pois, istream &stream)  =0;
	virtual ~CCodec(){}
};


now i have a derived class:
1
2
3
4
5
6
7
class CIndentCodec : public CCodec{
public:

	void write(ostream &stream, const vector<CWaypoint> &waypoints, const vector<CPOI*> &pois);
	void read(vector<CWaypoint> &waypoints, vector <CPOI*> &pois, istream &stream);
	~CIndentCodec(){}
};

with the associated methods (just for testing):
1
2
3
4
5
6
7
8
9
void CIndentCodec::write(ostream &stream, const vector<CWaypoint> &waypoints, const vector<CPOI*> &pois)
{
	cout <<"test";
}

void CIndentCodec::read(vector<CWaypoint> &waypoints, vector<CPOI*> &pois,istream &stream)
{
	cout  << "test";
}


when i try following:
CCodec *coder = new CIndentCodec;
which is a baseclass pointer allocating memory for a object of type CIndentCodec, the compiler tells me that i can not allocate an object of abstract type 'CIndentCodec'.

Do i miss something? Why does the compiler saying that the inherited class is abstract too? I have declared the methods so it should not be abstract?

thanks,
regards ensi



omg.... now is see the problem, there is the difference between one parameter....
When overriding a virtual function, favour using the override specifier;
give the compiler a chance to tell you about a possible error.
In a member function declaration or definition, override ensures that the function is virtual and is overriding a virtual function from the base class. The program is ill-formed (a compile-time error is generated) if this is not true.
http://en.cppreference.com/w/cpp/language/override
Topic archived. No new replies allowed.