CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011

    Is that sample code correctly?

    Could you say me is that code fully correctly?

    A Fun()
    A a = 0;
    return a;

    const A& a = Fun();
    A b = a;

  2. #2
    Join Date
    Oct 2008

    Re: Is that sample code correctly?

    to say it's "fully" correct, you should show us the definition of A ...

    anyway, supposing that A is non-explictly constructible from an int and that it is also copy constructible, it's correct.

    if you have doubts about the line "const A& a = Fun();", note that a temporary bound to a const reference will survive up to the end of the scope in which the reference is defined; so, again, it's ok.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)