Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

c++

Name: Anonymous 2012-07-16 19:25

/prog/, why doesn't this code compile?

It fails with "error: no matching function for call to 'forward(int&)'". As far as I can see I am only calling std::forward on a const int&.


#include <utility>
class Test
{
public:
    template <typename... Args>
    Test(Args... args)
    {}
};

template <typename... Args>
Test make_test(Args... args)
{
    return Test{std::forward<Args...>(args)...};
}

int main()
{
    auto x = make_test(5, 6);
    return 0;
}

Name: Anonymous 2012-07-16 19:43

It fails because there is no matching function call for 'forward(int&)'.

Name: Anonymous 2012-07-16 19:48

But I'm not calling forward(int&) anywhere!

Name: Anonymous 2012-07-16 22:15

>>3
make_test(5, 6);

Name: Anonymous 2012-07-17 14:39

FTFY



#include <utility>
class Test
{
public:
    template <typename... Args>
    Test(Args... args)
    {
    }
};

template <typename... Args>
Test make_test(Args... args)
{
    return Test{std::forward<Args>(args)...};
}

int main()
{
    auto x = make_test(5, 6);
    return 0;
}

Don't change these.
Name: Email:
Entire Thread Thread List