Home > Back-end >  There seems to be a mistake in the Effective C
There seems to be a mistake in the Effective C

Time:10-06

In the third edition item35, "Effective c + + Chinese version of" the third sentence code on page 175
EyeCandyCharacter ecc1 (HealthCalculator ()); It seems to be wrong, the author aims to define a class object ecc1
But here the compiler will argue that this code is a function declaration,

I do not know if seen Effective c + + classmates

CodePudding user response:

Know the students give back to a, study together, the points of what are small

CodePudding user response:

No problem, the function declarations must have the type of parameter, such as:
MyClass test1 (int);//test1 is a function parameter is int, the return value is the MyClass

Int GetIntValue () {return 1; }
MyClass test2 (GetIntValue ());//test2 is an instance of the MyClass, initialized with function GetIntValue return values

CodePudding user response:

refer to the second floor dataxdata response:
, function declarations must have the parameter type, such as:
MyClass test1 (int);//test1 is a function parameter is int, the return value is the MyClass

Int GetIntValue () {return 1; }
MyClass test2 (GetIntValue ());//test2 is an instance of the MyClass, initialized with function GetIntValue return values




Then you help me to look at this piece of code, comments section complains

#include
#include
#include
#include
#include
#include
#include
using namespace std;
The class CAL.
Typedef STD: : tr1: : function Myfun;
The class myClass {
Public:
Int operator () (cal& P) {
Printf (" nihao \ n ");
return 0;
}
};
The class CAL {
Public:
CAL: (myfun f) fun (f) {
}
Int the print () {
Coutreturn 0;
}
Private:
Myfun fun;
};
Int first (cal& P) {
Printf (" nidaye \ n ");
return 0;
}
Int main () {
CAL a (first);
Amy polumbo rint ();
MyClass ha;
CAL b (ha);
//CAL b (myClass ());
P. rint ();
return 0;
}

CodePudding user response:

An error because CAL class defines only CAL (myfunc) constructor, there is no definition of CAL (MyClass) constructor

CodePudding user response:

The
reference 4 floor dataxdata reply:
an error because CAL class defines only CAL (myfunc) constructor, there is no definition of CAL (MyClass) constructor



It may not seem like it, if the commented code next line commented out then is not an error, is obviously the comment section when the statement
  • Related