最赞回答 / qq_慕虎1144658
通俗点说就是大的调小的,普通函数可读可写,const只可读,所以你用普通的调const肯定满足啊,但是反过来,你const修饰的对象,去调普通函数,这个函数要求可读可写,你用const去调就明显不满足了嘛 就相当于 我拿10块钱肯定可以买5块的东西,5块钱买不了10块钱的东西
2018-02-12
const Coordinate *p=&coor改成const Coordinate *p;p=&coor;可以通过
#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(int x, int y)
{
m_iX=x;
m_iY=y;
}
public:
int m_iX;
int m_iY;
};
int main()
{
Coordinate *p=new Coordinate(1,2);
cout <<"("<<p->m_iX<<"," <<p->m_iY<<")"<< endl;
delete p;
p=NULL;
return 0;
}
using namespace std;
class Coordinate
{
public:
Coordinate(int x, int y)
{
m_iX=x;
m_iY=y;
}
public:
int m_iX;
int m_iY;
};
int main()
{
Coordinate *p=new Coordinate(1,2);
cout <<"("<<p->m_iX<<"," <<p->m_iY<<")"<< endl;
delete p;
p=NULL;
return 0;
}