2

Good day, sirs and mams )

I've just got some strange problem, while proging c++, using Code::Blocks 10.05, FreeBSD 9.1

Source in lib.cpp:

class A{
  public:
    A();
    A(var1, var2);
};
A::A(){ imlementation }
A::A(va1, var2) {implementation }
class B : public A{
  public:
    B();
    B(var1, var2);
};
B::B() : A() {} // this is Astr#
B::B(var1, var2) : A(var1, var2) {} // this is Bstr#

Source in lib.h:

class A{
  public:
    A();
    A(var1, var2);
};
class B : public A{
  public:
    B();
    B(var1, var2);
};

Source in main.cpp:

#include "lib.h"
...
int main(){
  ...
  B* Bptr = new B();
  B* Bptr2 = new B(var1, var2);
  ...
}

And I get these build warnings:

.../lib.cpp||In constructor 'B::B(var1, var2)':
.../lib.cpp|Bstr#|warning: will never be executed
.../lib.cpp||In constructor 'B::B(var1, var2)':
.../lib.cpp|Bstr#|warning: will never be executed
.../lib.cpp||In constructor 'B::B()':
.../lib.cpp|Astr#|warning: will never be executed
.../lib.cpp||In constructor 'B::B()':
.../lib.cpp|Astr#|warning: will never be executed
||=== Build finished: 0 errors, 4 warnings ===|

This warnings appear only in Debug mode, Release build seems goes ok. The code builds and runs fine, but what I'm doing wrong?

4

2 回答 2

3

B(var1,var2)lib.h 中的构造函数是私有的。

于 2013-01-11T07:27:05.547 回答
0

警告:永远不会被执行

是 GCC 的警告,可以使用-Wunreachable-code. -Wunreachable-code非常不可靠,不应该使用;出于这个原因,在较新版本的 GCC 中,整个选项被完全删除。(实际上,并没有完全删除:命令行选项-Wunreachable-code仍然存在,但它不再做任何事情。)

于 2013-01-11T07:16:59.500 回答