Search code examples
c++vxworks

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 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!


Solution

  • 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.