Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768).

SOLVED
Go to solution
Highlighted
agh
Occasional Contributor

When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768).

Hi,

 

Using aC++ 6.26, the following code fails to compile.

#include <vector>

template <typename T>
class Container
{
    std::vector<T> m_container;

public:
    void add(const T &value)
    {
        m_container.push_back(value);
    }

    void add(T &&value)
    {
        // Cannot do this as std::move is not implemented in aC++.
        //m_container.push_back(std::move(value));
        m_container.push_back(value);
    }
};

int main()
{
    Container<double> container;
    int item = 5;
    container.add(item);
}

 The failure is:

"rvaluetest.cxx", line 26: error #3768: an rvalue reference cannot be bound to
          an lvalue
      container.add(item);

 Which is strange, since I have overloaded the add function to take an rvalue reference as well as a const lvalue reference.

 

Surely, the compiler should pick the rvalue reference method instead of the lvalue one?

 

To me this looks like a defect in the compiler, but is there a workaround?

1 REPLY
Ashutosh_Nema
Occasional Visitor
Solution

Re: When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768

This was a compiler defect in A.06.26 release & got fixed in A.06.27 release.

We recommend to use latest compiler to avoid such defects.

 

Regards

Ashutosh Nema | HP-UX C/C++ Compilers Team.