在编写类时,您是否将相同类型的成员变量组合在一起?这样做有什么好处吗?例如:
class Foo
{
private:
bool a_;
bool b_;
int c_;
int d_;
std::string e_;
std::string f_;
...
};
Run Code Online (Sandbox Code Playgroud)
相反:
class Bar
{
private:
std::string e_;
bool a_;
int d_;
bool b_;
std::string f_;
int c_;
.
Run Code Online (Sandbox Code Playgroud)
..};
或者你只是按照它们被添加的顺序拥有它们?
Fed*_*oni 12
我根据语义对它们进行分组,即
class Foo
{
private:
std::string peach;
bool banana;
int apple;
int red;
std::string green;
std::string blue;
...
};
Run Code Online (Sandbox Code Playgroud)
越可读,越好.
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |