Branimir Maksimovic wrote:
> ....
> It isn;t clear to me following example:
>
> class A{
> public:
> A(){}
> A(A&){}
> };
>
> A foo(){ return A(); }
>
> int main()
> {
> A a;
> a = foo();
> }
>
> g++ gives strange error:
>
> cctor.cpp: In function A foo():
> cctor.cpp:7: error: no matching function for call to A::A(A)
> cctor.cpp:4: note: candidates are: A::A(A&)
> cctor.cpp: In function int main():
> cctor.cpp:12: error: no matching function for call to A::A(A)
> cctor.cpp:4: note: candidates are: A::A(A&)
Returning a tem****ary from 'foo' requires copy-constructing
another tem****ary (allowed to be optimized away, but semantially
should still be possible). But the only copy c-tor in 'A' takes
a ref to non-const A. The ref argument for 'A(A&)' cannot be
bound to the tem****ary, and that would probably be a clearer
message...
>
> I don;t have msvc handy but I think saw somewhere,
> that, it compiles without error.
... unless you disable language extensions ..
> So, perhaps, as g++ wants A(A) this is similar to
> your question.
> As I never used non const reference copy constructor,
> I'm really confused about it's behavior.
> It seems to me that compiler writers are too ;)
I don't believe that's the case (about the writers).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


|