您的位置:程序门 -> c/c++ -> c++ 语言



编译通过,但是连接出错,请问是什么原因?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


编译通过,但是连接出错,请问是什么原因?
发表于:2008-01-23 09:49:04 楼主
代码如下:

c/c++ code
#include <iostream.h> #include <string.h> const int len=50; class station { protected: char fromstation[len]; char tostation[len]; public: station(char fs[],char ts[]) { strcpy(fromstation,fs); strcpy(tostation,ts); } void inputvalue() { cout<<"enter from station:"; cin>>fromstation; cout<<"enter to station:"; cin>>tostation; } void display() { cout<<"going from "<<fromstation<<" station to "<<tostation<<" station"; } }; class mile { protected: int mile; public: mile(int m) { mile=m; } void inputmile() { cout<<"enter mile:"; cin>>mile; } void display() { cout<<"is "<<mile<<" miles"; } }; class price:public station,public mile { int price; public: price(char ff[],char tt[],int mm,int pp):station(ff,tt),mile(mm) { price=pp; } void getprice() { station::inputvalue(); mile::inputmile(); cout<<"enter price:"; cin>>price; } void display() { station::display(); mile::display(); cout<<",the price is "<<price<<endl; } }; void main() { price a("beijing","shanghai",1200,50); a.display(); }
发表于:2008-01-23 09:56:121楼 得分:0
连接报的什么问题?在我的vc6上面是好的啊。

going   from   beijing   station   to   shanghai   stationis   1200   miles,the   price   is   50
press   any   key   to   continue
发表于:2008-01-23 09:56:212楼 得分:0
错误呢?
发表于:2008-01-23 09:57:083楼 得分:0
哪里报错了?   vs2003编译链接正常
发表于:2008-01-23 10:03:554楼 得分:0
vs2005通过...
你用的是
#include   <iostream.h>
不是在vc下吗?可能跟环境设置有关
发表于:2008-01-23 10:05:055楼 得分:0
--------------------configuration:   learn2   -   win32   debug--------------------
linking...
libcd.lib(wincrt0.obj)   :   error   lnk2001:   unresolved   external   symbol   _winmain@16
debug/learn2.exe   :   fatal   error   lnk1120:   1   unresolved   externals
执行   link.exe   时出错.

learn2.exe   -   1   error(s),   0   warning(s)
发表于:2008-01-23 10:07:186楼 得分:0
在调试的时候,其他的程序也是有这个类似的异常提示信息~,如果是设置的问题,应该怎么样解决呢??
初学这个系统,对环境的配置不是很了解。
下面的程序也是类似的提示:
c/c++ code
#include <iostream.h> #include <stdlib.h> const int len=50; class stack { protected: int head; int stack[len]; public: stack(){head=0;} void push(int val) { head++; stack[head]=val; } int pop() { int temp; temp=stack[head]; head--; return temp; } }; class opstack:public stack { public: int push(int val) { if(head>len) { cout<<"stack underflow!"<<endl; exit(1); } return stack::pop(); } }; class usestack:public opstack { public: void productstack() { int val; cout<<"input data:"; cin>>val; while((val<0) || (val>100)) { cout<<"input error!"<<endl; cout<<"please input again:"; cin>>val; } opstack::push(val); } }; void main() { usestack a; a.productstack(); a.productstack(); cout<<"->"<<a.pop()<<endl; cout<<"->"<<a.pop()<<endl; }
发表于:2008-01-23 10:14:147楼 得分:0
要用
#include   <iostream>
using   namespace   std;
发表于:2008-01-23 10:24:108楼 得分:0
编写console程序,   请不要建立win32工程.
你的连接器在找winmain入口函数呢.

建一个console工程,   自然就会找你的main入口函数了.
发表于:2008-01-23 10:31:599楼 得分:0
刚才重新启动了一遍系统,便没有上面的哪些不对劲了呢~~
也不知道是什么原因呢~~

建立的是win32工程,编写的内容是上面的代码。

谢谢楼上的几位哥们了!!
发表于:2008-01-23 10:42:2310楼 得分:0
c/c++ code
#include <iostream> [color=#ff0000]//修改的地方[/color] #include <string> [color=#ff0000]//修改的地方[/color] using namespace std; [color=#ff0000]//修改的地方[/color] const int len=50; class station { protected: char fromstation[len]; char tostation[len]; public: station(char fs[],char ts[]) { strcpy(fromstation,fs); strcpy(tostation,ts); } void inputvalue() { cout<<"enter from station:"; cin>>fromstation; cout<<"enter to station:"; cin>>tostation; } void display() { cout<<"going from "<<fromstation<<" station to "<<tostation<<" station"; } }; class mile { protected: int mile; public: mile(int m) { mile=m; } void inputmile() { cout<<"enter mile:"; cin>>mile; } void display() { cout<<"is "<<mile<<" miles"; } }; class price:public station,public mile { int price; public: price(char ff[],char tt[],int mm,int pp):station(ff,tt),mile(mm) { price=pp; } void getprice() { station::inputvalue(); mile::inputmile(); cout<<"enter price:"; cin>>price; } void display() { station::display(); mile::display(); cout<<",the price is "<<price<<endl; } }; int main() [color=#ff0000]//修改的地方[/color] { price a("beijing","shanghai",1200,50); a.display(); }

楼主这样修改就可以了,你试一下,要是在不行的话咱们在研究
发表于:2008-01-23 16:33:3611楼 得分:0
在建产工程的时候选成了gui项目,改成console项目就不会有上面的问题了.

在编译选项里把/subssytem:windonws改成/subsystem:console或都删掉就行了.


快速检索

最新资讯
热门点击