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()
//...
};
Now i am using abo开发者_JAVA百科ve 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!
There is no visible error from your question. One problematic thing I see is that you are instantiating OMStaticArray<Concept>
where Concept = MyVar*
; so,
Concept *theLink; ==> MyVar **theLink;
Now your AllocateMemory()
returns void*
;
Are you sure you want to convert void*
into MyVar**
? Due to C-style casting you are not noticing that, but that statement is not convincing.
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
class Foo {...};
OMColloction< Foo > myFooCollection;
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.
精彩评论