C++ 文件连接问题
//queue.hconst int size=10;
class Queue{
public:
void Init();
void EnQueue(int newEleme);
int DelQueue();
int GetLength(){
return length;}
void Print();
private:
int elem[size];
int length;
int first;
};
//queue.cpp
#include <iostream.h>
#include "queue.h"
void Queue::Init()
{int first=length=0;
}
void Queue::EnQueue(int newElem)
{int pos=(first+length);
elem[pos]=newElem;
length++;
}
int Queue::DelQueue()
{int ret=elem[first];
first=first+1;
length--;
return ret;
}
void Queue::Print()
{ int pos=first;
cout<<"Queue:";
for(int i=0;i<length;i++,pos++)
{cout<<elem[pos];
}
cout<<endl;
}
//main.cpp
#include <iostream.h>
#include "queue.h"
void main()
{ Queue q;
int i;
cout<<"Initial state:"<<endl;
q.Init();
cout<<"Queue length="<<q.GetLength()<<endl;
q.Print();
cout<<"Adding"<<size<<"elements"<<endl;
for(i=0;i<size;i++)
q.EnQueue(i);
cout<<"Queue length="<<q.GetLength()<<endl;
q.Print();
}
分别编写queue.h,queue.cpp,main.cpp 三个程序,运行main.cpp
出现以下错误:
error LNK2001:unresolved external symbol "public: void__this Queue::EnQueue(int)"(?EnQueue@Queue@QAEXH@Z)
error LNK2001:unresolved external symbol "public: void__this Queue::Print(void)"(?Print@Queue@QAEXXZ)
error LNK2001:unresolved external symbol "public: void__this Queue::Init(void)"(?Init@Queue@QAEXXZ)
[[it] 本帖最后由 s1y2z3 于 2008-12-7 11:04 编辑 [/it]]