c++ Multiple parents with same variable name
问题 class A{ protected: int var; }; class B{ protected: int var; }; class C : public A, public B {}; What happens here? Do the variable merges? Can I call one in specific like, B::var = 2, etc. 回答1: You class C will have two variables, B::var and A::var . Outside of C you can access them like this (if you change to public: ), C c; c.A::var = 2; Attempting to access c.var will lead to an error, since there is no field with the name var , only A::var and B::var . Inside C they behave like regular