调用类的成员函数时出现了expected primary-expression before'const'的错误

zygup 2017-03-07 10:53:32
#include<iostream>
using namespace std;

const int MaxSize = 50;
typedef int DataType;

class PQueue
{
private:
DataType pqlist[MaxSize];
int count;
int rear, front;
public:
PQueue(void){rear = front = 0;count = 0;}
~PQueue(void){delete [] pqlist;}

void PQInsert(const DataType & item) //考虑到删除元素和输出元素都需要优先级最高的,直接在插入之后就进行排序
{
if (count == MaxSize)
{
cerr<<"Priority queue overflow!"<<endl;
return;
}
pqlist[rear] = item;
rear = (rear + 1) % MaxSize;
count++;

DataType temp; //将pqlist写入数组a,进行排序
DataType a[count];
int h = front;
for(int k=0; k<count; h=(h+1)%MaxSize)
{
a[k] = pqlist[h];
k++;
}
for(int i=0; i<count-1; i++) //冒泡排序
{
for(int j=count-1; j>i; j--)
{
if(a[j] < a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
h = front; //将排序完毕的数组重新写入队列
for(int k=0; k<count; h=(h+1)%MaxSize)
{
pqlist[h] = a[k];
k++;
}
}

void PQDelete(int n) //传递进入删除元素数量,删除并输出;
{
if(count > 0)
{
front = (front + n)% MaxSize;
count-=n;
for(int i=front; i<=rear; i++)
{
cout<<pqlist[i]<<" ";
}
}
else if(n > count)
{
cerr<<"The deleting number is wrong!"<<endl;
return;
}
else
{
cerr<<"Deleting from an empty priority queue!"<<endl;
return ;
}
}
};

int main()
{
int num;
PQueue test;
cin>>num;
DataType a;
for(int i=0; i<num; i++)
{
cin>>a;
test.PQInsert( const DataType & a); //报错!
}
int input;
cin>>input;
for(int j=0; j<input; j++)
{
cin>>a;
test.PQInsert( const DataType & a); //报错!!
}
int delnumber;
cin>>delnumber;
test.PQDelete(delnumber);
return 0;
}
...全文
3153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zygup 2017-03-07
  • 打赏
  • 举报
回复
总之还是非常感谢您,谢谢前辈
zygup 2017-03-07
  • 打赏
  • 举报
回复
一楼的方法很对,很轻松的解决了我的问题。 我查询了一些途径之后,报错语句的意思是要带基本表达式,于是我把DataType加了括号,把const方法去掉,也编译通过了。。 根本原因应该是我实例化的方法不对
幻夢之葉 2017-03-07
  • 打赏
  • 举报
回复
报错的语句改为 test.PQInsert(a); //传入实参 a

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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