| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 527 人关注过本帖
标题:C++ 文件连接问题
只看楼主 加入收藏
s1y2z3
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-11-29
收藏
 问题点数:0 回复次数:5 
C++ 文件连接问题
//queue.h
const 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]]
搜索更多相关主题的帖子: 文件 
2008-12-07 11:01
peng_piao
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2008-11-5
收藏
得分:0 
#include <iostream.h>
重复包含吧,把两个都去掉,然后在 .h文件里加上这个头文件
2008-12-07 20:08
s1y2z3
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-11-29
收藏
得分:0 
我改了一下,不是这种情况!
2008-12-08 09:49
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
用得vc??
你先编译一下queue.cpp就没有问题了

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2008-12-08 11:14
woshiyun
Rank: 1
等 级:新手上路
威 望:2
帖 子:348
专家分:0
注 册:2008-6-16
收藏
得分:0 
编译运行没有问题,结果对错我不管啊。
你确定你要先编译queue.cpp,然后编译main.cpp
2008-12-08 11:15
jdh99
Rank: 2
来 自:南师大
等 级:论坛游民
威 望:1
帖 子:59
专家分:15
注 册:2008-11-7
收藏
得分:0 
你的问题不在编译方面,你的初试化有问题。
void Queue::Init()
{int first=length=0;
}
去掉int

作鲲鹏,遨游于天地沧海
2008-12-08 17:20
快速回复:C++ 文件连接问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015031 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved