我正在努力使用下面的代码。基本上,我有一个Foo类和一个嵌套的Bar类,现在我想将Bar object类的指针传递给一个函数,但它不能编译。有人能帮我这个忙吗?谢谢。
template <typename T>
struct Foo
{
struct Bar
{
T data_;
};
Bar bar_;
};
template <typename T>
void func(Foo<T>::Bar* bar) // Why is this line wrong???
{
}
int main()
{
Foo<int> foo;
foo.bar_.data_ = 17;
func(&foo.bar_);
return 0;
}发布于 2012-03-24 01:23:16
这是一个dependent name,你需要说:
template <typename T>
void func(typename Foo<T>::Bar* bar) // Tell the compiler explicitly it's a typehttps://stackoverflow.com/questions/9843671
复制相似问题