i have the following two classes:
class MyClass
{
friend ostream& operator<<(ostream&, const MyClass& );
friend int operator+(const MyClass &, const MyClass &);
public:
MyClass(const int );
MyClass(const int, const int);
MyClass (const MyClass *, const MyClass *);
~MyClass();
MyClass& operator++();
void printValue();
void setValue(int);
int getValue() const;
private:
int value;
};
class DevClass : public MyClass
{
public:
DevClass(const int, const char *s);
char getId() const;
void setId(char *s);
private:
char id;
};
Implementation of operator++ is the following:
MyClass& MyClass::operator++()
{
this->value +=1;
return *this;
}
Now, if I use the operator with the derived class:
DevClass *dev=new DevClass(10,'c');
++dev;
"dev" seems to point somewhere else in memory. Why ? Why friend operator are not inherited ? This is a class exercise, so i need to address the problem.
Thank you !.