Help about pointers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H
I cant figure out how to do something. Here is waht my code look like

Class B //bas

void function1()
while(...)



}
}

Class A : public B //inherits from class

int myVar


I would like to be able to change the value of myVar each loop in the base Class
How can I do that using pointer? (Even if i have to create additional functions

Thanks in advance for your help.
 
No, you should not modify the derived class members from the base class
because it adds high coupling between the base class and the subclass
concrete implementation. Instead you need to use virtual methods. For
example:

class B
{
virtual void ModifyMembers() = 0;
void function1()
{
while( ...)
{
ModifyMembers();
...
}
}
};

class A : public B
{
int myVar;
void ModifyMembers()
{
// set the value on myVar as desired
}
};
 
Back
Top