LoginSignup
0
1

More than 5 years have passed since last update.

c++ クラスの基本 データメンバとゲッタの命名

Posted at

データメンバとゲッタの命名

c++ ではデータメンバとゲッタの名前を同一にできない。

  1. データメンバとゲッタ名を異なる名前にする
Class C{
    int number;
    int full_name;
  public:
    int no() {return number;}
    int name() {return full_name;}
}
  1. データメンバ名に下線をつける
Class C{
    int no_;
    int name_;
  public:
    int no() {return no_;}
    int name() {return name_;}
}
  1. ゲッタの先頭にget_をつける
Class C{
    int no;
    int name;
  public:
    int get_no() {return no;}
    int get_name() {return full_name;}
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1