我想做这样的事情:
template<class T>
class BaseSubscriber {};
template<class T>
class BasePublisher
{
// not working : invalid use of template-name 'BaseSubscriber' without an argument list
typedef BaseSubscriber SubscriberType;
// compiling
typedef BaseSubscriber<T> SubscriberTypeT;
};
template< template<class T> class Subscriber, class Data >
class ClassA:
public Subscriber<Data>
{
};
template< template<class T> class Publisher, class Data >
class ClassB:
public Publisher<Data>
{
// Ok, but I want that the type "BaseSubscriber" depends on the template parameter Publisher
void method1(ClassA<BaseSubscriber, Data>&);
// I want something like that. But how to define SubscriberType ?
void method2(ClassA<Publisher<Data>::SubscriberType, Data>&);
// or (SubscriberType only depends on the Publisher, nor on the Data)
void method2(ClassA<Publisher::SubscriberType, Data>&);
// Error : template argument is invalid
void method3(ClassA<Publisher::SubscriberTypeT, Data>&);
};
是否可以定义一些SubscriberType
可用于classA
模板参数的内容?或者有什么解决办法吗?
如果可能的话,我想保留classA
原型。我不想改变它
template<class TSubscriber > classA {};
而且我不能使用 C++11。非常感谢你的回答。