Use of static members of base class in inherited classes

Hi,

I am looking for a little input on the following code structure. I have 3 classes: A,B,C. Class A is the base class, whereas classes B and C inherit from this base class. In a nutshell, I am trying to assign members of classes B/C to the values held by the members of Class A. To do this, I am setting each member of class A to be static, filling the members of Class A with the desired value, then in Classes B/C assigning the values held by the members in Class A to members in these derived classes. I was told this was a wrong approach, however it seems to achieve what it was intended to do. Does anyone know why this is a "wrong approach," and what would be the proper alternative? Thanks.
Hi tbalestri,

if you're using inheritance, you automatically have access to public and protected data members of the base class, so you do not need to make any variables static.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class A {
	protected:
		float a;
	public:
		//[...]
};

class B : public A {
	private:
		float b;
	public:
		//Constructor
		B() {
			b = a;
		}
};
Topic archived. No new replies allowed.