C++ 错误枚举和 CRTP

Gui*_*e07 2 c++ enums crtp

template<class T>
struct broker
{
    typedef T typeBroker;
    static std::vector<std::string> extractListBroker(const std::string& broker)
    {
        std::vector<std::string> vec;

        if(broker.empty())          
        {
            for(int i=0;i<typeBroker::nbBroker;++i)
                vec.push_back( typeBroker::listBroker[i] );         
        }           
        else
        {
            typedef boost::tokenizer<boost::char_separator<char> > my_tok;

            boost::char_separator<char> sep( ";" );

            my_tok tok( broker, sep );

            for ( my_tok::const_iterator i = tok.begin(); i != tok.end(); ++i )  
                vec.push_back( *i ); 
        } 
        return vec;
    }

        std::string brokerToStr(typename typeBroker::BROKER i) //<--Problem here !!
    {
        return typeBroker::listBroker[i];           
    }
};


struct brokerDisTradable  : broker<brokerDisTradable>{
    std::vector<std::string> listBroker;
    brokerDisTradable()
    {
        listBroker.push_back("BRIDGE1" );
        listBroker.push_back("BRIDGELONDON" );
        listBroker.push_back("RECY" );
        listBroker.push_back("CURRENEX" );
    }
    static const int nbBroker = 2;
    enum BROKER  { BRIDGE1, BRIDGELONDON, RECY, CURRENEX };
};
Run Code Online (Sandbox Code Playgroud)

errro : 错误 C2039: 'BROKER' : 不是broker_def::brokerDisTradable' 的成员

任何想法?

谢谢!

Joh*_*ell 5

不能在基类的函数声明中使用派生类型的内部类型,因为派生类型的内部类型尚未定义,仅声明了派生类型。

有很多方法可以解决这个问题,包括类型特征参数和附加模板参数,并且在Base 中使用 Derived 中定义的类型在comp.lang.c++.moderated的奇怪重复模板模式中对它们进行了完美的讨论:http ://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/a99148265cb43680/b2581e058ffe8c91?#b2581e058ffe8c91