
class myClass { private: struct margin { int bottom; int left; int right; int top; } public: struct getmargin(); voID setmargin(string which,int value);}; 但是如何在函数setmargin()中设置与字符串“which”对应的struct的属性?例如,如果我调用myClass :: setmargin(“left”,3),我怎么能将“margin.left”设置为“3”?最好在保持结构POD的同时?我真的无法弄清楚这一点……
从旁注来看,这真的比编写许多getter / setter方法更好吗?
谢谢!
解决方法 首先,你的想法很糟糕…… 总结以上是内存溢出为你收集整理的c – 按变量值访问struct属性全部内容,希望文章能够帮你解决c – 按变量值访问struct属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)