简体   繁体   English

模板类中的双嵌套类正向声明

[英]double-nested class forward declaration inside a template class

I'm got "15:14: error: too few template-parameter-lists" when compiling next code using g++ 4.6.2 使用g ++ 4.6.2编译下一个代码时出现“ 15:14:错误:模板参数列表太少”

template <class T>
class A
{
public:
    class B
    {
    public:
        class C; //forward declaration
    };
    class D
    {
    //using B
    };

    class B::C // error here
    {
    //using D
    };
//using B::C
};

/* works fine, but required into "A"
template <class T>
class A<T>::B::C
{
public:
};
*/

How to solve the problem without changing the sequence of declarations? 如何在不更改声明顺序的情况下解决问题?

As you discovered, you don't define forward-declared classes in an inner scope, you must do it at the corresponding outer scope. 如您所知,您没有在内部作用域中定义前向声明的类,而必须在相应的外部作用域中进行定义。 Your "works fine" code seems to compile fine with g++ 4.5. 您的“工作正常”代码似乎可以在g ++ 4.5中正常编译。 Are you saying that when you try the "works fine" way line 19 gives an error? 您是说当您尝试“正常工作”时,第19行给出了错误吗? That's because it's missing a terminating ; 那是因为它缺少一个终止符; .

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

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