调用类的成员函数时出现了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;
}