「C++入門」クラスのコンストラクタを使うサンプル
書式
class クラス名
使用例
#include <iostream>
using namespace std;
// クラスの定義
class TestClass {
public: // アクセス修飾子
TestClass() { // コンストラクタ
cout << "Study skill and become smart"<<endl;
cout << "this is a test";
}
};
int main() {
TestClass myObj; //オブジェクトを作成
return 0;
}
実行結果
Study skill and become smart
this is a test