camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
I was making some templates to partially simulate C# properties in C++ when I ran into the problem that I couldn't inherit the assignment operator, which is weird. So, I tried something trivial like:
Needless to say, the above code doesn't work =/
I made the operator virtual because the inheriting class may want to override it.
Code:
class Base {
public:
virtual
Base& operator= (int val) {
i = val;
}
int i;
};
class Derived : public Base { };
int main () {
Base b;
Derived d;
b = 8; //OK
d = 7; //Error: no operator "=" matches these operands
return 0;
}
I made the operator virtual because the inheriting class may want to override it.