D
derek.google
I have some production code that doesn't compile with GCC 3.4 but
works with GCC 3.3, VC8, and Comeau, so I'm wondering if this is a
compiler issue or if I'm doing something wrong. Stripped down, this is
the code in question:
class Foo {
public:
Foo() {}
private:
Foo(const Foo&); // Line 5, noncopyable by design
};
const Foo& operator<<(const Foo& foo, int) {
return foo;
}
int main() {
Foo() << 42; // Line 13
}
The error is this:
test.cpp:5: error: `Foo::Foo(const Foo&)' is private
test.cpp:13: error: within this context
What I don't understand is why the compiler is trying to invoke the
copy ctor in the first place. It seems like there shouldn't be any
copying going on, so GCC shouldn't care that the copy ctor is private.
Thanks.
Derek
works with GCC 3.3, VC8, and Comeau, so I'm wondering if this is a
compiler issue or if I'm doing something wrong. Stripped down, this is
the code in question:
class Foo {
public:
Foo() {}
private:
Foo(const Foo&); // Line 5, noncopyable by design
};
const Foo& operator<<(const Foo& foo, int) {
return foo;
}
int main() {
Foo() << 42; // Line 13
}
The error is this:
test.cpp:5: error: `Foo::Foo(const Foo&)' is private
test.cpp:13: error: within this context
What I don't understand is why the compiler is trying to invoke the
copy ctor in the first place. It seems like there shouldn't be any
copying going on, so GCC shouldn't care that the copy ctor is private.
Thanks.
Derek