【发布时间】:2011-11-01 14:11:14
【问题描述】:
我有以下代码:
class TR_AgentInfo : public tuple<
long long, //AgentId
string, //AgentIp
>
{
public:
TR_AgentInfo() {}
TR_AgentInfo(
const long long& AgentId,
const string& AgentIp,
)
{
get<0>(*this) = AgentId;
get<1>(*this) = AgentIp;
}
long long getAgentId() const { return get<0>(*this); }
void setAgentId(const long long& AgentId) { get<0>(*this) = AgentId; }
string getAgentIp() const { return get<1>(*this); }
void setAgentIp(const string& AgentIp) { get<1>(*this) = AgentIp; }
};
现在我想使用这段代码:
int count = tuple_size<TR_AgentInfo>::value;
但是 gcc 给出了这个错误:
error: incomplete type std::tuple_size<TR_AgentInfo> used in nested name specifier
现在我该怎么办?
【问题讨论】:
-
但实际问题是什么?好像元组大小总是 2,那为什么是体操呢?
-
我的代码过于简化了!这些代码将由我自己制作的一个 TemplateGenerator 生成,然后在另一个非常通用的模板库中使用。
-
为什么不将元组大小存储为静态类常量?或者 typedef 元组,以便您以后可以使用
std::tuple_size<MyClass::tuple_type>::value? -
我希望子类有像元组一样的行为。
-
如果您的课程已完成,请说
namespace std { template<> struct tuple_size<TR_AgentInfo> { static const size_t value = 2; }; }。明确允许向命名空间添加特化。
标签: c++ templates compiler-errors tuples c++11