代码改变世界

g++ error/warning list

2012-12-02 13:33  robturtle  阅读(849)  评论(0编辑  收藏  举报

warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second.

note: 一般出现在原生类型的隐式类型转换中,比如在类中重载了 Class::operator[](unsigned), 但却用 Class[0] 而不是 Class[0u] 来调用。

error: passing 'const T' as 'this' argument of 'FUNC' discards qualifiers

note: 使用 const 类调用了非 const 方法

error: std::ios_base::ios_base(const std::ios_base&) is private

note: 对流类的使用方法都是通过引用

error: ‘...’ cannot be used as a function

note: 典型的命名冲突,将冲突的变量改名即可

可是有的时候会在很奇妙的地方报错,比如在初始化列表中少打了一个括号

CMake: undefined referenct to 'STH'

CMake: target_link_libraries (target liba libb) : 如果liba对libb有依赖关系,liba 必须排在前面!

error: two or more data types in declaration of ‘type name’

一般来说是模板无法展开参数时出现这种情况,不过这个 ‘type name' 所指的是 C++11 新增的类型声明语句:

using type_t = ...;

先检查一下你是不是漏了写分号吧。然后才是检查模板参数的问题。

c++ has incomplete type (does not have any field named "")

类或结构体的前向声明只能用来定义指针对象或引用,因为编译到这里时还没有发现定义,不知道该类或者结构的内部成员,没有办法具体的构造一个对象,所以会报错。 
将类成员改成指针就好了。

error: request for member ... in ... which is of non-class type

 

class foo {
    foo() {}
};

int main()
{
    foo f(); // compile error: g++ will think it as a function declare 'foo(void)'
}

 

使用无参构造函数的时候不要加括号。。。