dlist.h头文件的一部分定义如下:
#ifndef __DLIST_H__
#define __DLIST_H__
#include <iostream>
class emptyList {};
template <typename T>
class Dlist {
public:
bool isEmpty() const;
private:
struct node {
node *next;
node *prev;
T *o;
};
node *first; // The pointer to the first node (NULL if none)
node *last; // The pointer to the last node (NULL if none)
};
#include "dlist.cpp"
#endif
当我创建一个像这样的dlist.cpp文件:
#include "dlist.h"
template <typename T>
bool Dlist<T>::isEmpty() const
{
return !first and !last;
}
我在第4行得到错误信息:重新定义了 'bool Dlist::isEmpty() const'。
如果我删除
#include "dlist.h"
,我会在第4行得到错误:在 '&' 令牌之前需要初始化程序。这里需要帮助吗?是不是有什么我做错了,不允许我仅仅从 dlist.h 文件中定义函数?谢谢。
}
括号,它不应该在那里。我猜是打错了? - wimh