VC++的编译错误信息让人很迷惑啊

来源:互联网 发布:复杂网络涉及哪些学科 编辑:程序博客网 时间:2024/06/07 15:40

随便写了下面的这段代码。

#include <iostream>
using namespace std;

class CBase
{
public:
    const string& Name() {        return "CBase";    }


    void CallInternally(){       

cout<<Name()<<endl; // error here

}

};

编译器马上提示了如下错误, 看了半天没明白! :-( 

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion) 


后来发现是#include <string>没有写造成的。这出错信息太迷惑人了!

不仅如此,其他很多时候,如果某个type找不到,出错信息不是这样,但也是很能迷惑人的。



原创粉丝点击