【发布时间】:2012-01-29 17:46:22
【问题描述】:
我正在尝试在 Eclipse 中创建一个链表类,但无法正确编译。
这是我的 .cc 文件(代码片段)
#include <iostream>
#include "list.h"
using namespace std;
template <class T>
bool List<T>::isEmpty()
{
return (firstNode == NULL);
}
这是我的 list.h 文件(代码片段)
#ifndef __LIST_H__
#define __LIST_H__
template <typename T>
class List {
public:
bool isEmpty();
private:
struct node {
node *following;
node *previous;
T *contents;
};
node *firstNode;
};
#include "list.cc"
#endif /* __LIST_H__ */
我在 Eclipse 中尝试“Building All”,但出现以下错误:
make all
Building file: ../list.cc
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"list.d" -MT"list.d" -o "list.o" "../list.cc"
../list.cc:13: error: redefinition of 'bool List<T>::isEmpty()'
../list.cc:13: error: 'bool List<T>::isEmpty()' previously declared here
make: *** [list.o] Error 1
请帮忙...谢谢。我很乐意提供任何需要的说明
编辑:我得到了 .h 文件,所以我知道它是正确的。我也知道我应该有一个名为 list.cc 的 .cc 文件(它包含在 .h 文件的末尾)
【问题讨论】:
-
尝试将
isEmpty设为内联或静态。 -
@Nosrettap,文件名是什么?是
list.cc还是dlist.cc?您需要在问题中非常清楚实际文件名是什么。list.h或dlist.h? -
@Aaron McDaid,很抱歉。一切都应该是 list.h 但我认为这不是问题所在。我已经进行了适当的更改
标签: c++ eclipse compilation