當我編譯下面的C++代碼:C++中對象實例化的語法是什麼?
#include "ConstantList.h"
using namespace std;
int main() {
ConstantList* cl = new ConstantList();
//do something with cl
delete cl;
cl = NULL;
return 0;
}
編譯器給我的錯誤:
Undefined symbols:
"ConstantList::~ConstantList()", referenced from:
_main in ccNfeeDU.o
"ConstantList::ConstantList()", referenced from:
_main in ccNfeeDU.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
我沒有獲得用於實例化對象的語法對不對? 我ConstantList.h文件看起來像這樣:
#ifndef ConstantList_h
#define ConstantList_h
#include <string>
#include "Token.h"
using namespace std;
class ConstantListTail;
class ConstantList {
public:
ConstantList();
~ConstantList();
std::string toString();
void push_back(Token*);
void push_back(ConstantListTail*);
private:
Token* termString;
ConstantListTail* constantListTail;
};
#endif
任何幫助,不勝感激!
[「在G ++ Cpp中未定義的引用」的可能重複(http://stackoverflow.com/questions/6978241/undefined-reference-to-in-g-cpp) – 2013-02-22 17:40:33