我不确定为什么不使用 g++ 编译以下代码:
t.cpp: In instantiation of ‘Distrib<double>’:
t.cpp:28:56: instantiated from ‘Sampler<Distrib<Solution<double> > >’
t.cpp:35:48: instantiated from here
t.cpp:16:45: erreur: ‘double’ is not a class, struct, or union type
t.cpp:18:43: erreur: ‘double’ is not a class, struct, or union type
我期待能够AtomType
在嵌套模板中传播类型……</p>
#include <iostream>
#include <vector>
template<typename T>
class Solution
{
public:
typedef T AtomType;
};
template<typename SOLT>
class Distrib
{
public:
typedef typename SOLT::AtomType AtomType;
typedef std::vector<AtomType> Matrix;
Matrix matrix;
};
template<typename DT>
class Sampler
{
public:
typedef typename DT::AtomType AtomType;
typedef typename Distrib<AtomType>::Matrix Matrix;
Matrix matrix;
};
int main()
{
Sampler< Distrib< Solution<double> > > sampler;
}