LIFE LOG(ここにはあなたのブログ名)

あつあつ備忘録

ソフトやハード、時にはメカの備忘録をまとめていきます

2019-05-27から1日間の記事一覧

【C++】オブジェクトのポインタ

オブジェクトのポインタ オブジェクトポインタを使用した演算子は、他のデータ型のポインタ演算と同様に、そのオブジェクト型に関して行われる オブジェクトポインタをインクリメントすると次のオブジェクトを指すようになり、デクリメントするとその逆にな…

【C++】オブジェクトの配列

オブジェクトは変数を持っており、他の変数と同じ機能と属性を持っている オブジェクト配列へのアクセス方法も、ほかの変数配列と同じ study108.cpp #include <iostream> using namespace std; class samp { int a; public: samp( int n ) { a = n; } int get_a() { re</iostream>…

【C++】フレンド関数

関数をクラスのメンバにすることなく、関数からクラスの非公開メンバにアクセスすることができる 1つの関数から、2つ以上のクラスの非公開メンバにアクセスしたい時などに使われる。 クラスの宣言の内部にfriendを先頭につけて関数のプロトタイプを含める s…

【C++】関数からオブジェクトの返し

関数にオブジェクトを渡すことができるように、返すこともできる。 #include <iostream> #include <cstring> using namespace std; class samp { char s[80]; public: void show() { cout << s << "\n"; } void set( char * str ) { strcpy( s, str ); } }; samp input() { char</cstring></iostream>…

【C++】関数へオブジェクトの引き渡し

関数に引数としてデータを渡すのと同じように、オブジェクトを渡すこともできる。 study86.cpp #include <iostream> using namespace std; class samp { int i; public: samp( int n ) { i = n; } void set_i( int n ) { i = n; } int get_i() { return i; } }; void s</iostream>…

【C++】オブジェクトの代入

「オブジェクト1=オブジェクト2」のような書き方で代入できる。 study79.cpp #include <iostream> using namespace std; class myclass { int a, b; public: void set( int i, int j ) { a = i; b = j; } void show() { cout << a << ' ' << b << "\n"; } }; int main</iostream>…