繁体   English   中英

g ++中的“预期类型说明符”错误

[英]“expected type-specifier” error in g++

我有DD班

template<typename T>
class DD
: public IEnumerable<T>
{
    typedef IEnumerable<T> Super;
    typedef std::set<T*> Container;

和方法

template<typename T>
bool DD<T>::Enumerator::Move()
{
    if(!mIt.get()) 
       mIt.reset(
          new Container::iterator( <-----
            mContainer.GetContainer().begin()
          )
       );
       ... 
}

当我编译类时,出现error: expected type-specifier Container::iterator()什么问题?

尝试:

new typename Container::iterator

当您使用C ++模板时,编译器不知道Container :: iterator是类型还是其他类型。 因此,您需要明确地说这是一种类型。

另一方面,用new创建迭代器几乎肯定是错误的。

new typename Container::iterator( 
//  ^^^^^^^^

如果没有typename ,那么当X在模板中时,C ++将假定X::Y是成员(值/函数)。 您需要使用typename来强制编译器将X::Y解释为类型。

使那个

new typename Container::iterator(

有关详细说明,请参阅此常见问题解答

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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