C ++ getters和setters最好的风格 [英] C++ getters and setters best style

查看:370
本文介绍了C ++ getters和setters最好的风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java代码约定中简单明了,在这种风格:

in Java code convention is simple and obvious, in this style:

public:
    int GetMyAge(){
        return myAge;
    }
    void SetMyAge(int myAge){
        this->myAge = myAge;
    }
private:
    int myAge;

(我知道这是同样的事情,已经阅读了大部分的相关问题,我仍然不知道最好的一个和最官方的方式来做它在C ++。这不仅仅是偏好问题,可以吗?

(I know it's "again the same thing", but) I have read most of related questions on SO and I still don't know "the best one" and "the most official" way to do it in C++. It can't be just a matter of preferences, can it?

编辑:

看起来像可以

推荐答案

最好的风格是让你和你的团队制作高质量的软件,让你的客户继续支付你。

The best style is the one that allows you and your team to make quality software that your clients continue to pay you for.

这种风格如何为你和你的团队工作?你发现它导致(或防止)错误吗?你觉得维护代码容易吗?

How does this style work for you and your team? Do you find it causes (or prevents) bugs? Do you find it easy to maintain the code? Do you bicker about the formatting?

回答这些问题,您的问题的答案就会出现。

Answer those questions and the answer to your question will arise out of them.

这篇关于C ++ getters和setters最好的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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