Consider the following code.
#include <iostream>
class A
{
public:
using T = float;
A(const T& x)
{
m_value = x;
}
T& value();
private:
T m_value;
};
// A::T& A::value()
// {
// return m_value;
// }
auto& A::value()->T &
{
return m_value;
}
int main()
{
A a(10.0);
std::cout<<a.value()<<std::endl;
return 0;
}
When compile using C++11, I get the following error.
error: ‘value’ function with trailing return type has ‘auto&’ as its type rather than plain ‘auto’
auto& A::value()->T &
^
The equivalent code (the commented function) is working fine. But I would like to use trailing return type.
Aucun commentaire:
Enregistrer un commentaire