2006-12-06から1日間の記事一覧
すべてのクラスの宣言部分を「クラス名.h」のファイルに入れる すべてのクラスの定義部分を「クラス名.cpp」のファイルに入れる クラスの定義部分の先頭に「#include "クラス名.h"」を入れる クラスを使うソース・ファイルの先頭に「#include "クラス名.h"」…
#include <iostream> class ITest{ private: int a; public: int get() {return a;} void set(int aa) {a = aa;} }; int main() { ITest t; t.set(15); std::cout << t.get(); return 0; }inline 関数名(引数) {内容} クラスのメンバー関数をインライン関数として定義</iostream>…
#include <iostream> class CTest{ private: int a; public: int get() const; void set(int aa); }; int CTest::get() const { return a; } void CTest::set(int aa) { a = aa; } int main() { CTest c; c.set(7); std::cout << c.get(); return 0; }constのついたメ</iostream>…
#include <iostream> void mul2(int * const a) { *a *= 2; } int main() { int x = 3; int *px = &x; mul2(px); std::cout << x; return 0; }わざわざconstを使うことで、この関数内でポインタの値が変更されない(できない)ことを、関数のユーザーやコンパイラに伝え</iostream>…
const int *p; int * const p; const int * const p; ポインタが指す先に格納されている値を変更できないconst宣言 ポインタ自体の値を変更できないconst宣言 ポインタが指す先に格納されている値も、ポインタ自体の値も変更できない
コンテナ名 表現するデータ構造 特徴 vector 単純な(配列的な)リスト 配列のように要素にアクセスできるがリスト演算は遅い list リスト 一定時間でリスト演算できるが、配列のようには要素にアクセスはできない stack スタック 最後に入った要素が最初に出…
#include <iostream> #include <vector> using namespace std; int main() { int d; vector<int> v; //メインループ while(1){ cout << "数値を入力してください(0で終了): "; cin >> d; if(d == 0) break; //リストにデータを追加 v.push_back(d); //リストにのデータを表示 cout <</int></vector></iostream>…
template<class T> class Point { public: Point(); Point(T sx, T sy); T x, y; }; template<class T> Point<T>::Point() { x = 0; y = 0; } template<class T> Point<T>::Point(T sx, T sy) { x = sx; y = sy; }</t></class></t></class></class>
template<class T> T minimum(T a, T b) { return (a < b) ? a : b; }</class>
int minimum(int a, int b) { return (a < b> ? a : b; } ? より前の条件 (a
#include <iostream> using namespace std; const int ERROR = 1; double divide(double a, double b) { if(b == 0) throw ERROR; return a / b; } int main() { double a, b, c; cout << "空白で区切って数を2つ入力してください: "; cin >> a >> b; try{ c = divide(</iostream>…
CORBA(Common Object Request Broker Architecture)とは、分散オブジェクト環境でオブジェクト同士がメッセージを交換するための標準仕様のことである。CORBAには、次の三つの特徴がある。 プラットフォームからの独立 特定のプラットフォームに依存せず、…