vendredi 26 juin 2015

the following c++ program does not compile and is displaying a variety of errors

So I was reading about auto and other C++11 std feature and made this program:

#include<iostream>
#include<tuple>
using namespace std;
template<typename T1, typename T2>
auto create_pair(const T1 &a, const T2 &b)
{

    pair<T1, T2> p(a, b);
    return p;

}
int main()
{
    auto p1 = create_pair(4, 5.6);
    pair<int, float> p(p1);
    cout << get<0>(p);
    cout << endl;
    cout << get<1>(p);
    return 0;

}

My question is whether auto can be used in the way prescribed here in the create_pair() function or there exists some other workaround this to achieve the same result.

The error message when compiled with gcc is this:

create_pair function uses auto type specifier without return type.

Aucun commentaire:

Enregistrer un commentaire