【发布时间】:2012-11-19 11:11:53
【问题描述】:
部分头文件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 文件中定义我的函数吗?谢谢。
【问题讨论】:
-
头文件中有一个
},它不属于那里。我猜错了? -
Defining templated functions in .cpp不要!
标签: c++