热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_45658815
weixin_45658815
4 年前
trueweixin_45658815

两段代码仅注释处不一样,为什么第二个代码会出错呢,求问大佬,谢谢!
一`

#include<iostream>
using namespace std;
class Sample
{
int x, y;
public:
Sample() { x = y = 0; }
Sample(int a, int b) { x = a, y = b; }
void disp()
{
cout << "x=" << x << ",y=" << y << endl;
}
};
void main()
{
Sample s(2, 3), *p = &s;//此处
p->disp();
}

二、

#include<iostream>
using namespace std;
class Sample
{
int x, y;
public:
Sample() { x = y = 0; }
Sample(int a, int b) { x = a, y = b; }
void disp()
{
cout << "x=" << x << ",y=" << y << endl;
}
};
void main()
{
Sample s(2, 3);
*p = &s;//此处有错误
p->disp();
}

你问我答
CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
为什么这个程序一直在报这个错误,按那个错误报告改也没有用,用别人电脑输出就没有这个&错误,是不是电脑的问题啊? 错误是图一,图二是别人电脑编译的?有没有人能帮我解答一下,谢谢啦
立即登录