inheriting from class of specialized self?

女生的网名这么多〃 提交于 2019-12-01 19:48:10

To inherit from a type, that type must be complete. A little rearranging solves things:

template<class category>
class any_iterator;

template<>
class any_iterator<void>
{ 
public:
    typedef any_iterator<void> any_iter_void;

    any_iterator() { }
    void foo() { }
};

template<class category>
class any_iterator : public any_iterator<void>
{ 
public:
    typedef any_iterator<void> any_iter_void;

    any_iterator() : any_iter_void() { }
};

int main()
{
    any_iterator<int> a;
    a.foo();
}

Token standard quotes:

C++11, §10/2:

The type denoted by a base-type-specifier shall be a class type that is not an incompletely defined class; this class is called a direct base class for the class being defined.

§9.2/2:

A class is considered a completely-defined object type (or complete type) at the closing } of the class-specifier.

n.m.

10/2:

The type denoted by a base-type-specifier shall be a class type that is not an incompletely defined class

It is one manifestation of the bug of MSVC: its lack of two-phase name resolution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!