Figure 2 is a function in the base class for height, figure 2 is the height in the derived class to private data reset value function, (book derived classes used in the base class data members to use the function interface, why I write is not correct, and I put all the get function is defined as a const type), please help me passing through the ignorance, thank you,
CodePudding user response:
GetHeight returns a temporary variable, you need to return int& Or int * assignment can proceed
CodePudding user response:
Oh, understand, thank you,
CodePudding user response:
Oh, understand, thank you,
CodePudding user response:
Oh, understand, thank you,
CodePudding user response:
Base class will setHieght ah, otherwise you get or set?
CodePudding user response:
reference 5 floor zjq9931 reply: base class will setHieght ah, otherwise you get or set? I want to set up and setHeight is pure virtual functions, only in the base class interface does not provide the specific implementation, I rewrite this function in the derived class, can you ('; ︵; `) CodePudding user response:
Getter is defined as a const, would violate the original meaning of the getter, another setter and getter there should be no coupling relationship, Like you this kind of situation, if will return to a reference or correct getter, height of private property will be useless, even it is better to public, because the public property also need to access through the class instance, and the return value can run naked, if the instance destructor, the pointer will silently fail,, Should put the height directly defined as protected, CodePudding user response:
refer to 6th floor LINUX/response: Quote: refer to the fifth floor zjq9931 reply: base class will setHieght ah, otherwise you get or set? I want to set up and setHeight is pure virtual functions, only in the base class interface does not provide the specific implementation, I rewrite this function in the derived class, can you ('; ︵; `) Members of the base class is private? Pure virtual functions is an abstract class, do you have a private member variables, member variables simply don't forget it, and get not pure virtual, the set is a pure virtual is a bit messy, CodePudding user response:
references on 7th floor cool west wing response: getter is defined as a const, would violate the original meaning of the getter, another setter and getter there should be no coupling relationship, Like you this kind of situation, if will return to a reference or correct getter, height of private property will be useless, even it is better to public, because the public property also need to access through the class instance, and the return value can run naked, if the instance destructor, the pointer will silently fail,, Should put the height directly defined as protected, Ok, thanks for big support, CodePudding user response:
refer to the eighth floor zjq9931 response: Quote: refer to the sixth floor of the LINUX/reply: Quote: refer to the fifth floor zjq9931 reply: base class will setHieght ah, otherwise you get or set? I want to set up and setHeight is pure virtual functions, only in the base class interface does not provide the specific implementation, I rewrite this function in the derived class, can you ('; ︵; `) Members of the base class is private? Pure virtual functions is an abstract class, do you have a private member variables, member variables simply don't forget it, and get not pure virtual set is a pure virtual upset ah, Good, I try,