简体   繁体   中英

“error: no viable conversion from tuple…” using make_tuple

I'm trying to have a function return std::tuple<Qstring, int> , but I'm getting this compiler error:

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

`error: no viable conversion from 'tuple<[...], typename __make_tuple_return::type>' to 'tuple<[...], int>'``

What am I doing wrong?

There's nothing wrong with this code. It compiles without any issues.

$ 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM