So, I'm a bit confused with how inheritance works in relation to variables. Let's say that I had the following class:

class Test
{
private:
int var1;
float var2;

public:
void getInfo(int,float);
void setStuff(int,float);
};

Now, let's suppose that I wanted to derive a class from that base class; I want the derived class to be able to access member functions from the base class to modify its own private variables, but not overwrite the variables of the base class. How would I define the derived class?

The derived class just calls the base classes public member functions, they can not change the value of private member data objects or call private functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.