2
2

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.

勉強記録 1日目 - Effective C++ 第3版 -

Posted at

 はじめに

はじめまして、私は大学でロボットを研究する研究室に所属しています。
私は、主にソフトウェアについて勉強しています。
使用している言語は、C++, python, javascriptです。
ROSも使っています。
C++, python, ROSについて勉強した記録を残そうと思います。
しばらくは、Effective C++ 第3版を読んでそれについてまとめていきます。
できるだけ、毎日投稿するつもりです。

Effective C++ 第3版 - イントロダクション -

デフォルトコンストラクタ

コンストラクタとは?
C++で、クラスの初期化を行うときに最初に呼ばれる特別な関数。

デフォルトコンストラクタとは?
初期化時に引数を取らないコンストラクタのこと。
もしくは、引数があってもデフォルト値が与えられているコンストラクタのこと。

下にデフォルトコンストラクタとデフォルトコンストラクタ以外のコンストラクタを使ったクラスのサンプルコードを書きます。

intro_default_constructor.cpp
# include <iostream>

// 初期化
/// デフォルトコンストラクタ:引数をとらないコンストラクタ
// もしくは、デフォルト値が与えられているコンストラクタ

class ClassA {
 public:
  ClassA(){};  // デフォルトコンストラクタ
  ~ClassA(){};
};

class ClassB {
 public:
  explicit ClassB(int a){};  // デフォルトコンストラクタではない
  ~ClassB(){};
};

class ClassC {
 public:
  explicit ClassC(int x = 0, bool b = true){};  // デフォルトコンストラクタ
  ~ClassC(){};
};

int main(int argc, char *argv[]) {
  std::cout << "intoro_default_constructor.cpp" << std::endl;
  ClassB test(5);
}

参考文献

https://www.amazon.co.jp/gp/product/4621066099/ref=dbs_a_def_rwt_hsch_vapi_taft_p1_i0

2
2
2

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?