This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
error: value-initialization of reference
- From: David Hammarwall <david dot hammarwall at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 10 Sep 2009 16:25:11 +0200
- Subject: error: value-initialization of reference
Hi,
I've got a problem using a library where I get the compiler error
"value-initialization of reference" (using gcc4.3.2). I've isolated
the problem to the following dummy example:
int DEFAULT_OBJ = 0;
class Class_With_Ref
{
public:
Class_With_Ref() : ref(DEFAULT_OBJ) {}
Class_With_Ref& operator=(const Class_With_Ref &v) {return *this;}
private:
int &ref;
};
struct Wrapper
{
// Wrapper(){} //Everything will work if this line is un-commented
Class_With_Ref test;
};
int main(int argc, char **argv) {
Wrapper t = Wrapper();
return 1;
}
Everything will work if I explicitly declare (the empty) default
constructor in the Wrapper struct, but this is a pain considering that
there are a plethora of structs that contains a Class_With_Ref
objects. Moreover, I did not have this issue with gcc 3. Also, the
assignment, Wrapper t = Wrapper(), is implemented in the library so I
cannot change it to e.g.,
Wrapper t,t2;
t=t2;
which works perfectly in the above example.
Does anybody have any insight here?
BR,
David