C++使用模板时从此处实例化错误

发布于 2024-11-27 02:06:57 字数 1548 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑叹一世浮沉 2024-12-04 02:06:57

您的问题没有明显的错误。我看到的一件有问题的事情是,您正在实例化 OMStaticArray,其中 Concept = MyVar*;所以,

Concept *theLink; ==> MyVar **theLink;

现在你的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> 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.

七颜 2024-12-04 02:06:57

您正在使用 IBM Rhapsody,对吧? Rhapsody 提供的容器是“引用容器”,但模板参数应该是容器要包含的类的指针,而不是指向类的指针。

例如,

class Foo {...};

OMColloction< Foo > myFooCollection;

就是你想要的。

注意:所有 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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文