“错误:没有可靠的转换来自元组......”使用make_tuple

时间:2016-03-05 13:27:53

标签: c++ stdtuple

我正在尝试返回函数std::tuple<Qstring, int>,但是我收到了这个编译错误:

std::tuple<QString, int> foo()
{
    auto fst = getFst();
    auto snd = getSnd();
    return std::make_tuple(fst, snd);
}
  

`错误:'tuple&lt; [...],typename __make_tuple_return :: type&gt;'没有可行的转换''tuple&lt; [...],int&gt;'``

我做错了什么?

1 个答案:

答案 0 :(得分:1)

此代码没有任何问题。它编译没有任何问题。

$ cat t.C
#include <QString>
#include <tuple>

std::tuple<QString, int> foo()
{
    QString fst = QString("fst");
    int snd = 2;
    return std::make_tuple(fst, snd);
}
$ g++ -std=c++11 -I/usr/include/QtCore -c -o t.o t.C
$ g++ --version
g++ (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.