Home > Back-end >  Beginners ask a few questions computer level 2 C, gives a detailed analysis, I choose and the answer
Beginners ask a few questions computer level 2 C, gives a detailed analysis, I choose and the answer

Time:03-26

CodePudding user response:

The first is the subject options to write wrong...
Second b is static, all objects share, XB (3) that is temporary objects, in the expression to calculate the results after the destructor, so in copying to d carried out a structure, b=1, the structure and destructor offset calculation, the result is equal to 2 + 3 + 1=6
The third parameter is not note speak function reference, here will perform a default copy structure, so in the speak function, so a local Animal object operation

CodePudding user response:

The second question is constructs the twice, took a destructor is right, so in the end b is 1, the problem of parsing said final 2 "b" is wrong, to XB (3) define the objects don't write object name only write parameter form is called temporary objects, learned, learned,

CodePudding user response:

reference 1st floor NorZ response:
the first subject options to write was wrong...
Second b is static, all objects share, XB (3) that is temporary objects, in the expression to calculate the results after the destructor, so in copying to d carried out a structure, b=1, the structure and destructor offset calculation, the result is equal to 2 + 3 + 1=6
The third parameter is not note speak function reference, here will perform a default copy structure, so in the speak function, etc. So operating a local Animal object

So call the Speak in the third question is the derived class object cast to the base class? The call Type is due to the transfer and so there is no coercion is address?

CodePudding user response:

reference 1st floor NorZ response:
the first subject options to write was wrong...
Second b is static, all objects share, XB (3) that is temporary objects, in the expression to calculate the results after the destructor, so in copying to d carried out a structure, b=1, the structure and destructor offset calculation, the result is equal to 2 + 3 + 1=6
The third parameter is not note speak function reference, here will perform a default copy structure, so in the speak function, etc. So operating a local Animal object

1 d option if there are two parameters in brackets is established?

CodePudding user response:

Yes,
Title overloaded +, -, * is a unary operator (plus, minus, address access operator), so as long as a parameter;/is a binary operator,

CodePudding user response:

reference weixin_50881013 reply: 3/f
Quote: refer to 1st floor NorZ response:
the first subject options to write was wrong...
Second b is static, all objects share, XB (3) that is temporary objects, in the expression to calculate the results after the destructor, so in copying to d carried out a structure, b=1, the structure and destructor offset calculation, the result is equal to 2 + 3 + 1=6
The third parameter is not note speak function reference, here will perform a default copy structure, so in the speak function, etc. So operating a local Animal object

So call the Speak in the third question is the derived class object cast to the base class? The call Type is due to the transfer and so there is no coercion is address?


Here you can't say strong, even if a subclass object strongly object pointer or reference to a base class object, if overloading the base class method, through the pointer or reference to a function call, still is a subclass of call function, this function within the operation of Animal object already has nothing to do with the outside world, in fact,

The division operator, the # 5 floor right, +, -, * not add and subtract by symbols, but/only division, to do a friend function, must want to two parameters,

CodePudding user response:

refer to 6th floor NorZ response:
Quote: refer to the third floor weixin_50881013 response:
Quote: refer to 1st floor NorZ response:
the first subject options to write was wrong...
Second b is static, all objects share, XB (3) that is temporary objects, in the expression to calculate the results after the destructor, so in copying to d carried out a structure, b=1, the structure and destructor offset calculation, the result is equal to 2 + 3 + 1=6
The third parameter is not note speak function reference, here will perform a default copy structure, so in the speak function, etc. So operating a local Animal object

So call the Speak in the third question is the derived class object cast to the base class? The call Type is due to the transfer and so there is no coercion is address?


Here you can't say strong, even if a subclass object strongly object pointer or reference to a base class object, if overloading the base class method, through the pointer or reference to a function call, still is a subclass of call function, this function within the operation of Animal object already has nothing to do with the outside world, in fact,

The division operator, the # 5 floor right, +, -, * not add and subtract by symbols, but/only division, to do a friend function, must want to two parameters,

Yes, I mean if d option with two parameters, the problem is choose d is established

CodePudding user response:

I see, the first question to the first three options have two understand: one is the plus or minus, address access operator overloading for non-members, one is to add and subtract by overloading for members (because the first operand is call its object, overloaded member function when the parameters of minus one), but d option is only one: to understand devide overloaded member function, therefore, choose d,
  • Related