2016-03-05 62 views
-1

我想有一個函數返回std::tuple<Qstring, int>,但我得到這個編譯器錯誤:「錯誤:從元組沒有可行的轉換......」用make_tuple

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>'``

我是什麼做錯了?

+0

我試過編譯類似這樣的東西(使用std :: string而不是QString),一切都很好編譯。你正在使用哪種編譯器和STL impl?我用libC++使用clang(trunk) – JVApen

+0

@JVApen在簡化它的時候,我解決了它;我的'snd'是用'auto',它實際上並不是一個int。 – Daenyth

+0

16K代表,你不知道如何寫一個MCVE? – juanchopanza

回答

0

這段代碼沒有問題。它編譯沒有任何問題。

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

你是對的。我使用'auto',我的'snd'實際上並不是一個int。 – Daenyth

相關問題