C++使用模板时从此处实例化错误
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编译器可以很好地编译该代码。
我有以下错误 错误:从 'OMCollection::OMCollection(int) [with Concept = MyVar*]' 实例化,
我得到以下行: OMCollection(int theSize =DEFAULT_START_SIZE): OMStaticArray(theSize) { 尺寸 = 尺寸; 我不知道
为什么我会遇到这些错误,任何人都可以帮助我如何解决这个问题。
谢谢!
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()
//...
};
Now i am using above collection as below
class MyVar
{
public :
// Constructors and destructors:
MyVar(int Index) { }
// ...
};
OMCollection<MyVar*> m_pCollVars;
When i am runing above code in vxworks6.8 C++ compiler i am getting following error
error: instantiated from 'OMStaticArray<Concept>::OMStaticArray(int) [with Concept = MyVar*]'
I am facing lot of errors like above. The code used to compile fine using VxWorks 5.5 compiler.
I have following error
error: instantiated from 'OMCollection::OMCollection(int) [with Concept = MyVar*]'
I am getting at following line:
OMCollection(int theSize =DEFAULT_START_SIZE):
OMStaticArray(theSize) {
size = theSize;
}
I have no clue why i am facing with these errors, can any one help me how this can be fixed.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题没有明显的错误。我看到的一件有问题的事情是,您正在实例化 OMStaticArray,其中
Concept = MyVar*
;所以,现在你的
AllocateMemory()
返回void*
;您确定要将
void*
转换为MyVar**
吗?由于 C 风格的转换,您没有注意到这一点,但这种说法并不令人信服。There is no visible error from your question. One problematic thing I see is that you are instantiating
OMStaticArray<Concept>
whereConcept = MyVar*
; so,Now your
AllocateMemory()
returnsvoid*
;Are you sure you want to convert
void*
intoMyVar**
? Due to C-style casting you are not noticing that, but that statement is not convincing.您正在使用 IBM Rhapsody,对吧? Rhapsody 提供的容器是“引用容器”,但模板参数应该是容器要包含的类的指针,而不是指向类的指针。
例如,
就是你想要的。
注意:所有 Rhapsody 容器都必须使用一个类实例化,而不是基本类型,因为 0 是基金类型的有效值,但是引用容器的容器结束标记。
You are using IBM Rhapsody, right? The containers Rhapsody provides are "reference containers" but the template parameter should be the class you what the containers to contain pointers to, not a pointer to class.
Eg
Is what you want.
NB: all the Rhapsody containers must be instantiated with a class never a fundamental type, as 0 is a valid value for a fund type but the end-of-container marker for the reference containers.