是否有方法用另一个类的模板参数实例化模板类(示例中的“A”)?
示例:
“A”类:
//A.h
template <size_t size>
class A
{
void doSmt()
{
// do something with size
}
};“B”类:
//B.h
#include "A.h"
template<typename V>
class B
{
void doSmt2(A<V> a) //Error Here
{
//do something with a
}
};我得到的错误:错误1
error C2993: 'V' : illegal type for non-type template parameter 'size' 发布于 2015-10-12 13:43:36
是。您的问题是V是一个类型参数,而size是一个size_t参数。把它们配起来。
template <std::size_t V>
class B
{
void doSmt2(A<V> a)
{
}
};发布于 2015-10-12 13:44:55
A的模板类型是非类型模板参数.在B中,我们有一个类型模板参数。这些是不相容的。您需要做的是将非类型模板参数类型添加到B中。
template<size_t size>
class B
{
void doSmt2(A<size> a)
{
//do something with a
}
};https://stackoverflow.com/questions/33082689
复制相似问题