【发布时间】:2014-03-22 04:35:50
【问题描述】:
我实际上相当确定我的问题的答案可以在之前创建的线程之一中找到。特别是Where and why do I have to put the "template" and "typename" keywords?,它对模板/类型名消歧有很好的解释。然而,我不知所措,因为我实际上无法将这个概念扩展到我的代码,即相互交互的类模板。
在这个线程中,我想我看到的错误与我在代码中遇到的错误相同。为什么答案是使用 A<B> 定义 typedef,其中 B 是类,而不是 A<T>,其中 T 是我们实际想要的类型名模板。
尽管如此,我尝试了这些选项都无济于事。这是代码。感谢您的帮助。
#include "testTemplateA.h"
template<typename A>
class testTemplateB {
public:
// none of these work
typedef testTemplateA<A> templateType;
typedef typename testTemplateA<A> templateType;
typedef typename testTemplateA<testTemplateB> templateType;
testTemplateB(templateType& TA) {}
~testTemplateB(void) {}
};
#include "testTemplateB.h"
template<typename A>
class testTemplateA
{
public:
testTemplateA(void) {}
~testTemplateA(void) {}
void callUponB(void) {
testTemplateB<A> g = testTemplateB<A>(this);
}
};
【问题讨论】:
标签: c++ templates typename class-template