Inherit operator + and == from "Virtual Base class" to "Template son"

Hi guys ,

I've a little(big) problem with the following code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Base{       // an abstract class 

protected:

	virtual Base* operator+(Base* matrix) const = 0; // pure virtual
	virtual bool operator==(Base* matrix) const = 0; // pure virtual


public:
// MORE CODE

	 Base() {};
	~Base() {};
};


using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template <class T>
class Matrix : public Base
{

private:
        LinkedList<T> *list;
	bool operator==(Base* matrix) const {return true;};
	Base* operator+(Base* matrix) const {return matrix;};

public:
// more fields 

	Matrix();
	~Matrix();
};



I need to overload == and + operators .Is it possible to do that ?
I've tried a few ways but nothing is working .
I'd appreciate your help .Thanks,Ron
Last edited on
Why do you need to overload it to support base class instances if the base class is meant to be purely abstract with purely virtual functions? I don't see the point of trying to compare or add a base with a matrix...in this case you only need to overload the functions for matrix class instances.
Last edited on
This reeks of operator abuse. You probably shouldn't be doing this.

Your operators don't even take the expected params. Adding a pointer to an object is nonsense. Having it return a pointer is even more nonsense.

You'll have to be more specific about what you're trying to accomplish (and why). Maybe we can suggest an alternative way to do it.
Topic archived. No new replies allowed.