c++中使用私有方法的属性
Properties using private methods in c++
我有这样一个类:
class Size
{
private:
int size_x;
int size_y;
int GetX( void );
int GetY( void );
void PutX( int x );
void PutY( int y );
public:
_declspec ( property ( get = GetX , put = PutX ) ) int X;
_declspec ( property ( get = GetY , put = PutY ) ) int Y;
};
这段代码不能工作,因为当我试图访问X或Y时,使用了私有方法。
我怎么能使一个属性,使用不能在类外使用的函数?
恐怕只能用另一种语言。标准c++没有这样的属性糖(可悲的是),虽然有一些hack,但没有一个是非常漂亮的,包括微软的。关于私有方法与Microsoft如何创建一个使用不能使用的函数的属性课外?
declspec(property)
扩展不兼容的具体问题,请参阅这里的更多讨论:http://blog.aaronballman.com/2011/11/an-almost-useful-language-extension/ 相关文章:
- 有没有一种方法可以创建具有广义属性的命名空间
- 我的类中有方法的指针数组,但我不能调用我的方法.代码如下
- 如何处理一个子类有方法,而另一个没有方法的子类?
- 有没有一种方便的方法可以从属性树中删除节点,同时保留其子节点
- 在JIT期间更新方法属性
- 有方法的类,我不明白类的外观
- 是否有方法为模板参数指定所需的定义
- 有没有任何方法可以从外部控制photoshop属性
- 是否有方法将相对库路径添加到可执行文件以避免设置LD_library_path
- 是否有方法将所有赋值运算符(+=、*=等)转发为隐式使用重写的直接赋值运算符(=)
- 是否有方法使用vector的内容作为键和自定义值来初始化unordered_map ?
- 在调用main函数之前,是否有方法解析命令行选项?
- 在c++中是否有方法对成员变量(类)进行后期初始化?
- 是否有方法为任何指针类型定义转换操作符
- 是否有方法为窗口窗体中的特定按钮挂钩鼠标事件
- 是否有方法检测内联函数ODR违规
- 在Windows Vista+上不注册proppage.dll,是否有方法访问远程过滤器图?
- 模板:只执行类中有方法的方法
- 是否有方法使Visual Studio对include区分大小写
- 是否有方法在调用函数时防止隐式的static_cast ?