Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ <;匿名>;在函数g+;中未初始化使用+;4.4_C++ - Fatal编程技术网

C++ <;匿名>;在函数g+;中未初始化使用+;4.4

C++ <;匿名>;在函数g+;中未初始化使用+;4.4,c++,C++,在使用g++4.4编译时,我遇到了这个编译错误 struct Class { Class() { } void Method() const; }; void f(); // undefined void g( Class x ) // pass by value { f(); // call undefined function x.Method(); // call method on parameter } void h() {

在使用g++4.4编译时,我遇到了这个编译错误

struct Class
{
    Class() { }
    void Method() const;
};

void f(); // undefined

void g( Class x ) // pass by value
{
    f();        // call undefined function
    x.Method(); // call method on parameter
}

void h()
{
    Class x;
    g( x );
}
使用这些标志进行编译时:

g++-Wuninitialized-O3-c-o a.out test.cpp

test.cpp:22:警告:“匿名”在此函数中未初始化使用

这仅在g++版本4.4中遇到


谁能告诉我出了什么问题吗?

这就是你要找的吗?即使将代码放入名称空间中,也无法解决此问题。尽管如此,我注意到(可能是错误的)当我在函数g()中通过引用传递类x时,警告消失了。这可能是荒谬的。正确的解决方案是什么。
void Method()const
缺少实现。添加一个主体使警告消失。但是,错误消息有点混乱。许多方法缺少实现,如f()。这就是为什么我在编译时使用了-c标志。我不认为这是问题所在。这就是你要找的吗?即使将代码放入名称空间中,也无法解决此问题。尽管如此,我注意到(可能是错误的)当我在函数g()中通过引用传递类x时,警告消失了。这可能是荒谬的。正确的解决方案是什么。
void Method()const
缺少实现。添加一个主体使警告消失。但是,错误消息有点混乱。许多方法缺少实现,如f()。这就是为什么我在编译时使用了-c标志。我认为这不是问题所在。