如何定义另一个模板类的内部模板类的构造函数
How to define the constructor of an inner template class of another template class?
我有另一个模板类的内部模板类:
// hpp file
template< class T1 > class C1
{
// ...
public:
// ...
C1();
template< class T2 > C2
{
// ...
C2();
};
};
当我声明内部类构造函数时,我会得到一些错误:
//cpp file
template<> C1< MyType >::C1()
{
// ...
}
template<> template< class T2 > C1< MyType >::C2::C2() // error: invalid use of template-name ‘class C1<MyType>::C2’ without an argument list
{
// ...
}
我也试过:
template<> template< class T2 > C1< MyType >::C2<T2>::C2() // error: invalid use of incomplete type ‘class C1<MyType>::C2<T2>’
{
// ...
}
类型不完整,但构造函数没有类型。。。
我有点困在这里了。如何申报?
执行以下操作:
template<typename T1>
template<typename T2>
C1<T1>::C2<T2>::C2()
{
}
不能通过定义内部模板类的方法来专门化外部类。如果你想专门化内部类和外部类,你可以:
template<>
template<>
C1<MyType>::C2<char>::C2()
{
// ...
}
实时
如果你想保持内部类的通用性,你应该首先专门化外部类:
template<>
class C1<MyType>
{
// ...
public:
// ...
C1();
template< class T2 > class C2
{
public:
// ...
C2();
};
};
然后定义类C2
、的构造函数
template<class T2>
C1<MyType>::C2<T2>::C2()
{
// ...
}
实时
相关文章:
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 为什么从另一个构造函数内部调用C++构造函数不修改类变量?
- C++构造函数具有内部链接,但未定义 [-Wundefined-internal]
- 班级成员在C Lambdas中捕获内部构造函数
- 用相同的参数将内部和外部构造函数分开
- 如何在类构造函数内部对同一类的成员函数启动pthread
- C++类的向量,不能在所述类的构造函数内部push_back
- C :如何通过其构造函数的参数初始化类内部矩阵的尺寸
- 在shared_ptr的复制构造函数内部
- 从构造函数中本地声明的device_vector使用device_vector::data()方法初始化结构内部的指针是
- 如何正确地从运算符构造函数内部调用复制构造函数
- gcc 4.7.3与构造函数一起使用make_shared时出现内部编译器错误
- 如何谷歌奇怪的字符,例如"~"内部问题,例如在构造函数之前的 c++ 中这意味着什么?
- 我应该在类构造函数内部还是外部初始化shared_ptr
- "this"指针在构造函数内部指向什么C++?
- dynamic_cast派生构造函数内部
- C++在子类内部调用基类构造函数
- 在boost::thread构造函数内部调用boost:;bind()时发生编译器错误
- 将内部构造函数切换为受保护的 typemap
- Qt:连接内部构造函数-将槽在对象初始化之前被调用