I see two issues that you should address, or at the very least better understand. They both boil down to the fact that you have not resolved the pure virtual declaration in your base class, ana
:
1) operator+(): Your class baba
defines a different + operator than the base class. In particular, ana::operator+()
is a unary + operator (accepts only one operand), while baba::operator+(baba& ali)
is a binary operator (accepts two operands) on baba
. You need to decide which to use and use it. If you want to use the binary + (which given your definition in baba
is what I think you want) then you declare in ana
:
virtual int operator+(const ana&) const =0;
and in baba
:
virtual int operator+(const ana& ali) const {return x+ali.x; }
Why this needs to be a pure virtual method in ana
, since x
is defined in ana
is curious. It will do interesting things if you have other derived classes that do things differently (losing commutivity is likely to result). But I expect you have your reasons, so I won't question further.
2) operator=(ana&): You also have a problem with the assignment operator declarations. Again, you're not resolving the pure virtual. In ana
you have:
virtual void operator=(ana&)=0;
while in baba
you have: void operator=(baba &ali)
. The arguments are different since baba&
is not the same as ana&
; so the pure virtual declaration is again not resolved. In order to fix this, you probably want to change the declaration in ana
to:
virtual void operator=(const ana&)=0
and in baba
:
virtual void operator=(const ana& ali) { x=ali.x; }
I have similar concerns as to why you want to declare this as a pure virtual since, again, it assumes that different derived classes will implement it differently leading to interesting behavior. Again, I'm sure you have your reasons.
I do hope this helps.
initial_state
fromerror_state
? It certainly seems to violate the first of my basic rules for operator overloading. – sbi