为了诱导类似 C#/Java 的语法,通过预处理命令重新定义 C++ 访问修饰符可能会产生什么影响?
#include <iostream>
// The access modifiers are redefined here.
#define public public:
#define protected protected:
#define private private:
class Halo
{
public Halo(int xx)
{
x = xx;
}
public int getX()
{
return x;
}
private int x;
};
int main()
{
Halo* halo = new Halo(3);
std::cout << halo->getX();
return 0;
}