使用模板时从这里实例化的c++错误
C++ error instantiated from here when using templates
template<class Concept> class OMAbstructContainer
{
friend class OMIterator<Concept> ;
// ...
};
template<class Concept> class OMStaticArray :
public OMAbstructContainer<Concept> {
protected:
Concept *theLink;
int count;
void* AllocateMemory(int size);
bool ReleaseMemory(void* pMemory);
public:
// Constructor
OMStaticArray(int size): count(0)
{
theLink = NULL;
theLink = (Concept*) this->AllocateMemory(size);
}
};
template<class Concept> class OMCollection :
public OMStaticArray<Concept>{
public:
// Constructor
OMCollection(int theSize=20):
OMStaticArray<Concept>(theSize) {
size = theSize;
}
// Destructor
~OMCollection() { } // The link is delete in ~OMFixed()
//...
};
现在我使用上面的集合如下
class MyVar
{
public :
// Constructors and destructors:
MyVar(int Index) { }
// ...
};
OMCollection<MyVar*> m_pCollVars;
当我在vxworks6.8 c++编译器中运行上述代码时,我得到以下错误
error: instantiated from 'OMStaticArray<Concept>::OMStaticArray(int) [with Concept = MyVar*]'
我面临着很多这样的错误。该代码用于编译精细使用VxWorks 5.5编译器。
我有以下错误error: instantiated from 'OMCollection::OMCollection(int) [with Concept = MyVar*]'
我得到以下行:OMCollection(int size =DEFAULT_START_SIZE):OMStaticArray(规模){size = size;}
我不知道为什么我面对这些错误,有人能帮助我如何解决这个问题吗?
谢谢!
你的问题没有明显的错误。我看到的一个问题是你实例化了OMStaticArray<Concept>
,其中Concept = MyVar*
;
Concept *theLink; ==> MyVar **theLink;
现在你的AllocateMemory()
返回void*
;
您确定要将void*
转换为MyVar**
吗?由于c风格的强制转换,你没有注意到这一点,但这种说法并不令人信服。
您正在使用IBM Rhapsody,对吗?Rhapsody提供的容器是"引用容器",但是模板形参应该是容器要包含指针的类,而不是指向类的指针。
如
class Foo {...};
OMColloction< Foo > myFooCollection;
就是你想要的。
注意:所有Rhapsody容器都必须用一个类实例化,而不是一个基本类型,因为0是基金类型的有效值,而是引用容器的容器结束标记。相关文章:
- 从C++实例化QML
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何创建一个空的全局类并在启动时实例化它
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 约束和显式模板实例化
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 对象实例化调用构造函数的次数太多
- 如何使用非默认构造函数实例化模板化类
- 静态数据成员模板专用化的实例化点在哪里
- 错误的cv::face FacemarkLBF实例化
- C++的解析器在可以区分比较和模板实例化之前会做什么?
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 检查某些类型是否是模板类 std::optional 的实例化
- 我有一个对象,它将在整个程序的持续时间内实例化,但一个类成员不会,我应该动态分配它吗?
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 模板化类构造函数的模板实例化
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- 受约束的成员函数和显式模板实例化
- 对显式实例化的模板函数的未定义引用
- [temp.variadic]中关于包扩展实例化的措辞