我有 C++ 方面的经验,但最近一直在工作中专门使用 python,我很生疏。下面列出了每个文件:
主文件
#include "stack.h"
int main(int argc, char** argv){
return 0;
}
堆栈.h
#ifndef STACK_H
#define STACK_H
#define NULL 0
template <class elementType>
class stack{
struct node
{
elementType data;
node* next;
};
node* top;
public:
stack(){
top = NULL;
}
~stack(){
node temp = top;
while (top != NULL){
top = top->next;
delete temp;
}
}
void push(elementType x){
node temp = new node();
temp.data = x;
temp.next = top;
top = temp;
}
elementType pop(){
node temp = top;
top = top->next;
return temp;
}
bool isEmpty(){
return top == NULL;
}
};
#endif //STACK_H
生成文件
a.out : main.o stack.o
gcc -o a.out main.o stack.o
main.o : main.cpp stack.h
gcc -O -c main.cpp
stack.o : stack.h
gcc -O -c stack.h
clean :
rm main.o stack.o
所以,当我cd
进入项目目录并输入时,make
我得到:
gcc -O -c main.cpp
gcc -O -c stack.h
stack.h:7:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
make: *** [stack.o] Error 1
我一直在寻找解决方案,但据我所知,我的代码是正确的。我不是在寻求实际堆栈实现的帮助,我意识到这段代码实际上不会对空的 main 做任何事情,但我似乎无法修复这个编译错误。