English 中文(简体)
为我的模板制作一个双倍链接清单的主持人的问题
原标题:Problems creating an iterator for my templated doubly linked list

我制造了一个双倍链接的清单,供我使用,我完成了名单的编写工作,但现在我试图给我增加一个炉子,但我对 this子规则的混淆。 这里的错误是:

error C2990:  d_list  : non-class template has already been declared as a class template

Here s the header file it s all located in:

/****************************/
/* d_list class             */
/* with exceptions classes  */
/****************************/
class d_list_error{};
class d_list_empty{};

template <class T>
class d_list_iter;

template <class T>
class d_list{
public:
    d_list();
    d_list(const d_list &_dl);
    d_list &operator=(const d_list &_dl);
    ~d_list();

    void push_back(T item);
    void push_front(T item);

    void pop_back();
    void pop_front();

    bool isEmpty() const;
    unsigned int size() const;

    void clear();
private:
    struct node{
        node *prev; 
        node *next;
        T    data;
    };
    node             *head;
    node             *tail;
    unsigned int     currSize;
    d_list_iter<T>   *dli;

    /* Utility Functions */
    void initFirstEle(T item, node* first);
    void copyAll(const d_list<T> &_dl);
};

/*************************/
/* d_list iterator class */ 
/*************************/

class d_iter_already_exists {};

template <class T>
class d_list_iter{
public:
    d_list_iter(const d_list &_dl);
    ~d_list_iter();
    T getNext() const;

private:
    friend class d_list;
    d_list<T>   *dl;
    node        *next;
    node        *prev;
    bool        valid;
};

根据这一规定,所有成员的职能都是为除名而确定的。 我已经开了给发件人写信。 d 名单完全基于我的测试。 我想象,我只是 errors倒,因为对我来说,这是一块未经许可的领土。

最佳回答

您必须具体说明分类申报之外的模板参数,以具体说明模板类型。

specifically, you should write (something like) d_list<T> instead of simply d_list within template <typename> class d_list_iter s declaration. this includes your use of friend.

no也是如此。 假设他们为示威游行而公开:

,而不是单纯的node<>template <typename> category d_list_iter

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签