S
Stub
Question 1:
class Count
{
public:
Count() : id(n++) { cout << id << " default ctor" << endl; }
Count(Count const&) : id(n++) { cout << id << " copy ctor" << endl;
Count (Count const& src) : v(src.v) { cout << "Count(Count const&) " << v
<< "\n"; }
};
void func(int& x) {//non-const ref
cout << x << endl;
}
What're the implication of "Count(Count const&)" above? Is it the same as
"Count(const &Count)"? Does it have anything to do with "Count(const Count
&c)"?
Question 2:
int main (){
const int My_const = 68;
//This works
func(const_cast<int&>(My_const));
//This will not work
//error C2440: 'const_cast' : cannot convert from 'const int' to 'int'
func(const_cast<int>(My_const));
return 0;
}
Can "const_cast" be used with "int", "long" directly like:
const_cast<int>(My_const))?
Why "func(const_cast<int&>(My_const))" seems like working? What's the
explanation if it's right way to remove constantness from the const int
My_const?
Thanks for your help!
class Count
{
public:
Count() : id(n++) { cout << id << " default ctor" << endl; }
Count(Count const&) : id(n++) { cout << id << " copy ctor" << endl;
Count (Count const& src) : v(src.v) { cout << "Count(Count const&) " << v
<< "\n"; }
};
void func(int& x) {//non-const ref
cout << x << endl;
}
What're the implication of "Count(Count const&)" above? Is it the same as
"Count(const &Count)"? Does it have anything to do with "Count(const Count
&c)"?
Question 2:
int main (){
const int My_const = 68;
//This works
func(const_cast<int&>(My_const));
//This will not work
//error C2440: 'const_cast' : cannot convert from 'const int' to 'int'
func(const_cast<int>(My_const));
return 0;
}
Can "const_cast" be used with "int", "long" directly like:
const_cast<int>(My_const))?
Why "func(const_cast<int&>(My_const))" seems like working? What's the
explanation if it's right way to remove constantness from the const int
My_const?
Thanks for your help!