Error:表达式必须包含整数或枚举类型?为什么呢?

#include "stdafx.h"
#include<iostream>
using namespace std;
class A
{
public:
A(int i,int j)
{
a=i;
b=j;
}
void move(int x,int y)
{
a+=x;
b+=y;
}
void show()
{
cout<<"("<<a<<","<<b<<")"<<endl;
}
private:
int a,b;
};
class B : public A
{
public:
B(int i,int j,int k,int l):A(i,j)
{
x=k;
y=l;
}
void show()
{
cout<<x<","<<y<<endl; //“,”Error:表达式必须包含整数或枚举类型
}
void fun()
{
move(3,5);
}
void f1()
{
A::show();
}
private:
int x,y;
};
int _tmain(int argc, _TCHAR* argv[])
{
A a(1,2);
a.show();
B b(3,4,5,6);
b.fun();
b.show();
b.f1();
system("pause");
return 0;
}

杨__羊羊
浏览 301回答 3
3回答

MMMHUHU

^操作符使用错了,^操作符在C/C++里面是按位异或的意思,所以a^b的话,a和b都需要时整数才行,你的是double肯定不行了。不过我想你是想计算平方,C里面指数运算需要调用函数pow

慕标琳琳

cout<<x<","<<y<<endl;漏写了<,应该是cout<<x<<","<<y<<endl;

慕田峪9158850

错误肯定不是你贴出来这句提示,你x后面应该是<<,你写的是<,你贴的这个错误可能是这个错误造成的其它问题,真正的错误应该","作为左操作数产生的。
打开App,查看更多内容
随时随地看视频慕课网APP