Derived classes

hello,I am trying to use the derived method from a pointer to the base class without making the Base class knowing any of Derived classes. (Tried to simplify the code in the best way). I don t know why it does not access automatically the derived class operator. Actually it does not compile cause it requires the operator Base to be public and anyhow it wouldn t access the Derived operator.
Does anybody know how to fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Base {
public:
	virtual ~Base() {};
	
protected:
	Base();
	virtual bool operator!=(const Base &that) const;
}

class Derived1  : public Base {
public:
	Derived1(char c) { myc = c;};
	~Derived1() {};
	
	bool operator!=(const Derived1 &that) const {
	
	return myc != that.myc;
	}
private:
        char myc;
}


class A {
public:
	A() {};
	void function(Base *that) {
		if (*that != *myV[0]  && *that != *myV[1]) {
			//do something
		}
	}
	
private:
	Base *myV[2];
}

client.cpp
#include "A.h"
#include "Derived1.h"

int main() {
	A my;
	my.function(new Derived1('a'));
	//my.function(new Derived2(1);
	
	return 0;
}
The function at L15 doesn't override the definiton L7 as the param is of a different type. L28 is trying to access Base operator!= which is protected and so cannot.
Thanks a lot man
Lets have two shapes. Are they identical?
If they are both triangles and identical size and angles, then yes.
If they are both circles with identical radii, then yes.
However, how do you test that the shapes are actually same subshape? All you have is refs to base.
Topic archived. No new replies allowed.