Is it possible to tell g++ to use the FOO& operator when constructing the FOO object ?
struct FOO {
FOO( FOO & foo ) { // non-const copy constructor
}
operator FOO&() {
return *this;
}
FOO( int i ) {
}
};
int main() {
FOO a(FOO(5));
}
I currently get the following error:
In function int main():
error: no matching function for call to FOO::FOO(FOO)
note: candidates are: FOO::FOO(int)
note: FOO::FOO(FOO&)
-- edit --
Note that I try to setup an object that can exchange the ownership of a resource.
Calling FOO foo1(foo) make foo to lose the ownership of the resource, this mean that foo cannot be const.
Also note that I want to avoid smart-pointer mechanism.
/Za(disable language extensions). – Xeo Mar 9 '12 at 15:19mutablekeyword. – Mike DeSimone Mar 9 '12 at 15:39