如何在c ++中编写Get / Set字段? [英] How to write Get/Set fields in c++?

查看:93
本文介绍了如何在c ++中编写Get / Set字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 public class Record 
{
public string Record_Identifier {get;组; }
}





如何用c ++编写相同的东西?

解决方案

如果您只需要获取并设置一个没有任何验证的值,只需使用一个公共变量 -

 class Record 
{
public :
string Record_Identifier;
}



现在你可以像这样使用它了 -

记录rcd; 
rcd.Record_Identifier =你好;
string var = rcd.Record_Identifier;


参考此CP帖子



< a href =http://www.codeproject.com/Questions/381254/Create-Set-Get-function-to-parameter-in-Cplusplus> Create-Set-get-function-to-parameter-in-Cplusplus [ ^ ]

public class Record
{
 public string Record_Identifier { get; set; }
}



How to write the same thing in c++?

解决方案

If you simply need to get and set a value without any validation simply use a public variable -

class Record
{
public:
    string Record_Identifier;
}


Now you will be able to use it like so -

Record rcd;
rcd.Record_Identifier = "Hello";
string var = rcd.Record_Identifier;


Refer this CP post

Create-Set-Get-function-to-parameter-in-Cplusplus[^]


这篇关于如何在c ++中编写Get / Set字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆