问一个弱弱的问题

hulooc07 2007-12-11 01:10:24
有关类定义的时候的一个问题:
------------------------- 头文件queue.h ---------------
const int ARRAY_SIZE = 10;
class Queue{
private:
int elem[ARRAY_SIZE];
int first;
int length;

public:
void Init();
void EnQueue(int newElem);
int DelQueue();
int GetLength(){return length;}
void Print() const ;
};

------------ 函数定义queue.cpp ---------
#include <iostream.h>
#include "queue.h"
void Queue::Init()
{
first = length =0;
}
void Queue::EnQueue(int NewElem)
{
int pos =(first + length)%ARRAY_SIZE ;
elem[pos]=NewElem;
length ++ ;
}
int Queue::DelQueue()
{
int ret = elem[first];
first = (first+1)%ARRAY_SIZE;
length --;
return ret;
}
void Queue::Print()
{
int pos=elem[first];
cout << "Queue:" ;
for (int i=0;i<length;i++)
{
cout <<elem[pos] << " ";
pos = (pos+1)%ARRAY_SIZE;
}
cout << endl;
}

出现的错误:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
queue.cpp
C:\Documents and Settings\潜伏爪牙忍受\queue.cpp(21) : error C2511: 'Print' : overloaded member function 'void (void)' not found in 'Queue'
c:\documents and settings\潜伏爪牙忍受\queue.h(2) : see declaration of 'Queue'
Error executing cl.exe.

queue.obj - 1 error(s), 0 warning(s)

使用的平台是VC++6.0 请各位帮忙指导
...全文
84 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hulooc07 2007-12-11
  • 打赏
  • 举报
回复
谢谢各位热心的前辈
thecorr 2007-12-11
  • 打赏
  • 举报
回复
声明与定义要一致。。不然编译器会认为是不同的函数的。。。
NKLoveRene 2007-12-11
  • 打赏
  • 举报
回复
上面声明的时候是void Print() const ;
后面的const怎么没了?
arfi 2007-12-11
  • 打赏
  • 举报
回复
void Queue::Print()

==>

void Queue::Print() const
effective_person 2007-12-11
  • 打赏
  • 举报
回复
void Queue::Print() //看看你的定义是否一样

33,321

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧