【问题标题】:Holding an array of T within a template<T> class在 template<T> 类中保存一个 T 数组
【发布时间】:2013-11-04 04:02:29
【问题描述】:

我正在尝试为队列开发模板类并收到错误error C3265: cannot declare a managed 'items' in an unmanaged 'TQueue&lt;T&gt;'。据我了解,我不能在非托管“类”中拥有托管类型。我的代码如下:

#pragma once

template<class T> class TQueue
{
private:
    array<T>^ items;
    int currentIndex;
    int count;
public:
    TQueue();
    void Enqueue(T toAdd);
    T Dequeue();

    GetCount() {return currentIndex;}
};

如何在队列中保存&lt;T&gt; 类型的数组?

提前致谢, J

【问题讨论】:

  • 您可能需要修正问题标题

标签: templates c++-cli queue adt


【解决方案1】:

只需在类原型中包含“ref”。我不小心删除了它,导致班级变得“不受管理”。

类原型最终为:template&lt;class T&gt; ref class TQueue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多