【发布时间】:2012-01-06 15:46:47
【问题描述】:
我正在尝试使用 Visual C++ 11 构建 googletest,但以下代码会导致错误
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t, // <-- error C2977
::std::ostream* os) {
PrintTupleTo(t, os);
}
这是一个错误文本:
f:\gtest-1.6.0\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments
c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(72) : see declaration of 'std::tuple'
还有utility-file的第72行:
template<class = _Nil, _MAX_CLASS_LIST>
class tuple; // Line 72
std::tuple 有什么问题以及如何解决?
(顺便说一句:我尝试将 std::tr1::tuple 更改为 std::tuple 失败)
【问题讨论】:
-
你包括
<tuple>吗? Visual Studio 的std::tuple最多支持 10 种类型,因此应该可以编译。它也应该通过 using 语句在std::命名空间中,这让我觉得要么你没有包含<tuple>,要么 VS11 有问题。 -
一个提醒,如果你有一个超过 5 个成员的元组。为了便于阅读,您可能更喜欢使用命名成员而不是 get
(aTuple) 定义一个类。对于大多数情况,默认复制 ctor 和 operator= 就足够了。
标签: c++ visual-studio-2012 c++11 tuples variadic-templates