0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++における構造体(struct) とクラス(class)の違いについての備忘録

Posted at

UnionFindの実装をしている時に知ったのだが、C++では構造体にメンバ関数をもったりコンストラクタを持ったりできるらしい。
調べてみたところ、C++における構造体とクラスの違いはメンバ変数のデフォルト(何も指定しない時)でのアクセスレベルの違いのみであるということだ。

構造体の場合デフォルトではpublic:、逆にクラスの場合はデフォルトではprivateなのだそうだ。

自分はC++超初心者かつ競プロしかしてないのであまりクラスや構造体を使ったコードを書くことはないのだが、たまたまライブラリを作る時に書かなければいけないときに、他の人が構造体の中でコンストラクタや関数を持っていたのでびっくり仰天した。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?