Well there are several possible errors you have here:
class2 x = new class1;
did you mean: ???
Code:
class2* x = new class1;
And this code only will work, if class1 is derived from class2.
Changing a value in a base class is only possible if the member is public or protected. Both is considered bad practice and best avoided. You can provide public/protected getter/setters, though, with the help of which you can do the intended changes.
Code:
class Base
{
bool m_bool;
public:
void set(bool b)
{
m_bool = b;
}
bool get()
{
return m_bool;
}
};
class Derived : public Base
{
public:
void someFunc()
{
set(false); // this sets the value of the Base class to false
}
};
/// in your main
Base* pBase = new Derived;
pBase->someFunc(); // call the set method of Base indirectly though someFunc
Is that what you need? If not, probably you postsome of you code, indicating where your error occurs.
Cheers,
D
Bookmarks