这是简单的代码:
int main()
{
int x=0;
std::cout<<x;
operator<<(std::cout,x); //ambiguous
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么operator<<(std::cout,x)电话不明确但不是std::cout<<x;?谢谢
这里的问题是输出整数,operator<<是一个std::ostream 成员函数.
So to explicitly call the operator function you should do e.g.
std::cout.operator<<(x);
Run Code Online (Sandbox Code Playgroud)
The stand-alone operator<< function is for characters and strings.
| 归档时间: |
|
| 查看次数: |
156 次 |
| 最近记录: |