b*******y 发帖数: 239 | 1 operator const char*()
一直不知道这个怎么理解,有人说说这个的特殊含义吗?
我知道一般的operator overload,但这个似乎连operator是什么都没有,所以很不理
解。
这个是C++的,请指点,非常感谢。 |
b*******y 发帖数: 239 | 2 原题也是在这个版上有人发的C++的其中一题,已copy下来:
class Person{
public:
Person(const char* szName);
const char* GetName() const;
/*put a function here*/
private:
char *m_szName;
};
int main()
{
Person person("John");
std::cout << Person;
return 0;
}
Referring to the sample code above, which one of the following member
functions do you add at the comment to support std::cout << person
statement?
A. std::string operator() { return GetName(); }
B. std::string ToString() { retur |
f****4 发帖数: 1359 | 3 conversion Operator :)
// code explains itself
class Test{
public:
operator const char*(){cout<<"Test"<
};
void f(const char*)
{
cout<<"f()"<
}
int main(){
Test t;
f(t);
return 0;
} |
b*******y 发帖数: 239 | 4 Thank so much for the help.
It's Conversion Operator, I didn't know this name. |