On 13 Gen, 01:51, LR <lr...@superlink.net> wrote:
You want to assign pointers of different types to each other?
No. That was an example showing that what Daniel Pitts said was not
the answer.
If you want to modify the int in Base that is inherited by derived, have
you considered something like this?
#include <iostream>
class Base {
int i;
public:
void SetI(const int ii) { i = ii; }
int GetI() const { return i; }};
class Derived : public Base {
public:
void SetI(const int ii) { Base::SetI(ii); }
int GetI() const { return Base::GetI(); }};
int main() {
Derived d;
d.SetI(34);
std::cout << d.GetI() << std::endl;
}
Well, it's an ugly workaround, because I'm going to reimplement all
the methods I need (maybe many), without reason. Usually, when you
want to reimplement a method from base class, it's due to the fact
that you need to add code inside for different behavior, in this case
it's only a call. This is against the inheritance purpose!
Derived.