首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

vc6.0中,简单程序的编译连接的LINK2001异常

2013-03-04 
vc6.0中,简单程序的编译连接的LINK2001错误刚开始学习C++,做书上的一个类的例子,先写了头文件:stack.h,然

vc6.0中,简单程序的编译连接的LINK2001错误
刚开始学习C++,做书上的一个类的例子,先写了头文件:stack.h,然后写了实现文件stack.cpp,然后又写了应用程序stacker.cpp,将这三个文件放在一个文件夹中,编译stack.cpp和stacker.cpp的时候都没有错误,但是当链接stacker.cpp的时候就出现了LINK2001的错误,下面是具体的代码和错误:
---stack.h---
#ifndef STACK_H_
#define STACK_H_
typedef unsigned long Item;
class Stack
{
private:
enum {MAX=10};
Item items[MAX];
int top;
public:
Stack();
bool isempty() const;
bool isfull() const;
bool push(const Item & item);
bool pop(Item & item);
};
#endif
---stack.cpp---
#include "stack.h"

Stack::Stack()
{
top=0;
}

bool Stack::isempty()const
{
return top==0;
}

bool Stack::isfull() const
{
return top==MAX;
}

bool Stack::push(const Item & item)
{
if(top<MAX)
{
items[top++]=item;
return true;
}
else 
return false;
}

bool Stack::pop(Item & item)
{
if(top>0)
{
item=items[--top];
return true;
}
else
return false;
}
---stacker.cpp---
#include<iostream>
#include<cctype>
#include"stack.h"
int main()
{
using namespace std;
Stack st;
char ch;
unsigned long po;
cout<<"Please enter A to add purchase order, \n"
<<"P to process a PO, or Q to quit.\n";
while (cin>>ch && toupper(ch)!='Q')
{
while(cin.get()!='\n')
continue;
if(!isalpha(ch))
{
cout<<'\a';
continue;
}
switch (ch)
{
case 'A':
case 'a':cout<<"Enter PO number to add: ";
cin>>po;
if(st.isfull())
cout<<"stack already full.\n";
else
st.push(po);
break;
case 'p':
case'P':if(st.isempty())
cout<<"stack already empty\n";
else
{
st.pop(po);
cout<<"PO # "<<po<<" popped\n";
}
break;

}
cout<<"Please enter A to add a purchase order, \n"
<<"P to process a PO,or Q to quit.\n";
}
cout<<"Bye\n";
return 0;
}

---链接错误---

Linking...
stacker.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack::pop(unsigned long &)" (?pop@Stack@@QAE_NAAK@Z)
stacker.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack::isempty(void)const " (?isempty@Stack@@QBE_NXZ)
stacker.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack::push(unsigned long const &)" (?push@Stack@@QAE_NABK@Z)
stacker.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack::isfull(void)const " (?isfull@Stack@@QBE_NXZ)
stacker.obj : error LNK2001: unresolved external symbol "public: __thiscall Stack::Stack(void)" (??0Stack@@QAE@XZ)
Debug/stacker.exe : fatal error LNK1120: 5 unresolved externals
执行 link.exe 时出错.



stacker.exe - 1 error(s), 0 warning(s)
希望可以得到高手的指导,谢谢!! C++ LINK2001 class
[解决办法]
加#include "stdafx.h"试试
[解决办法]
应该没错。
不知道楼主怎么弄的工程
[解决办法]

引用:
引用:代码本身应该没有问题。。话说VC下怎么能不建立工程呢?。。我就是想做个关于类的例子,所以就没有建工程


你怎么不建立一个工程试试呢?
VC下不建立工程什么都干不了。

反正你的代码是可以通过编译连接的。
g++下亲测

热点排行