#include
Using namespace STD.
Class a
{
Public:
int x;
A (int I=10)
{
X=I;
cout<& lt;" A: "& lt;}
};
Class b: public a
{
A, a.
int x;
Public:
B (int I) : (I)
{
X=I;
cout<& lt;" B: "& lt;}
};
Int main ()
{
B b (5);
return 0;
}
A: I want to know this: why is 10 x
CodePudding user response:
To understand what is a: : xCodePudding user response:
Default parameters, you did not show the superclass constructor calls B, but the compiler invocation, the inherited from the parent class B members are initialized to 10;CodePudding user response:
A: : x spelled wrong grammar, you find a standard compiler try will know,I know vc6 support this kind of writing, but he is wrong grammar, x is the static variables can be used to this kind of writing,
CodePudding user response:
Because you are in a class b extra defines int x; Although the same name with its parent class member variables, but not the same, and because of the same name, x will be hidden in a, need to specially designated to access to a of xCodePudding user response:
A class has a x, you why again to define a class b x. no one will be done in actual developmentCodePudding user response:
CodePudding user response:
Many idea is wrong, upstairs,1, the reason of your problems I've said above the
2, your grammar is no mistake, it is you have a problem naming conventions, classes generally begin with a capital letter, instances of the class will typically use a lowercase letter, you are totally opposite
CodePudding user response:
I wrong, that is a member function, me as an ordinary functionCodePudding user response:
I write this is reading programs on the Internet looking for the results of the title, format might be a little problem, but run there is no question that is not covered by the parameter name repetition, in another post, I found the answer, you are interested can go to the next: https://bbs.csdn.net/topics/396410092In general is an A (I) is the answer, I want A (I) without this, it would be 10
B (int I) : (I), A (I)//-- -- -- -- -- -- -- -- explicitly call A constructor, at this point A is no longer the default constructor argument, but I -- -- -- -- -- -- -- -- -- -- -- --
{
X2=I;
//A: at this time: the value of x is 5
Cout & lt; <"B:" & lt;
CodePudding user response: