クラス
//AutoPtr.h #include <cstring> #include <iostream> class AutoPtr { private: char *ptr; public: AutoPtr(); ~AutoPtr(); char *operator=(char *ptr); operator char* (); char& operator[](int index); //深いコピー AutoPtr(AutoPtr& src); AutoPtr& operator=(AutoPtr& </iostream></cstring>…
線形代数と固有値問題 ひととおり線形代数を学んだ後によむといいかもしれない。できれば、関数解析をちょっとやった後で。スペクトル分解とかの所は結構細かいところまで乗ってるので便利。へぇ、こんな方法でとけるのか、と。でも説明丁寧かといわれるとそ…
単語 rank3::1~~4 --> http://d.hatena.ne.jp/kenta11626918/20111012/1318401749 rank2 --> http://d.hatena.ne.jp/kenta11626918/20111006/1317882668 rank1 -->http://d.hatena.ne.jp/kenta11626918/20111017/1318821771 C34CAFDF85FFCEB9929CD40BD14E730…
class LessInt { public: bool operator()(const int& riLeft, const int& riRight) const { return riLeft ()); //と、あたかも、コンストラクタを呼び出しているがごとく見える. sort(a.begin(), a.end(), cmp) // このとき、クラスは入れ子にできるよ. …
class LessInt { public: bool operator()(const int& riLeft, const int& riRight) const { return riLeft ()); //と、あたかも、コンストラクタを呼び出しているがごとく見える. sort(a.begin(), a.end(), cmp) //
今回迷ったコード #include using namespace std; class PartSum { public: PartSum(int* array, int count, int cond) : m_count(count) { //m_array = array とやってしまうと、arrayをいじくることにより、メンバ変数m_arrayも代わってしまうので、止めた…
リスト作成して、ノードを挿入したい。 #include using namespace std; typedef struct _list { int data; struct _list *next; }MyList; class Node { public: Node(); ~Node(); private: MyList* m_head; public: void Insert(int num); void Disp(); }; N…
仕様: りんご、バナナ、トマト(野菜)、にんじんが商品である。 りんごの仕入れ値は300円、定価は400円。 バナナの仕入れ値は200円、定価は300円。 トマトの仕入れ値は30円、定価は50円。 にんじんの仕入れ値は50円、定価は70円。 それぞれ仕入れ数を入力…
virtual SellProductとしていたおかげで、 基底クラスのメンバ関数から読んだ場合などでも、本来の型に応じて呼び分けられる。 仮想関数はどんな状況でも、そのオブジェクトの本来の型のものが呼ばれる。 main.cpp #include "Product.h" #include "Fruit.h" …
Vegetable.h #ifndef VEGETABLE_H_ #define VEGETABLE_H_ #include "Product.h" class Vegetable : public Product { public: Vegetable(const int nCostPrice, const int nListPrice, int nRestCount); virtual ~Vegetable(); protected: bool m_bThuFlag; …
class Product virtual void Disp() const { //状態を表示 cout 仕入れ値:" constを付加する。 cout 仕入れた数:" 仕入れ額:" class Fruit virtual void Disp() const{ Product::Disp(); //ここは、constつけたので、OK! cout constオブジェクトは、constメ…
仕様: りんご、バナナ、トマト(野菜)、にんじんが商品である。 りんごの仕入れ値は300円、定価は400円。 バナナの仕入れ値は200円、定価は300円。 トマトの仕入れ値は30円、定価は50円。 にんじんの仕入れ値は50円、定価は70円。 それぞれ仕入れ数を入力…
動的にメモリを確保する練習というか、復習。 int main() { //intの大きさのメモリを確保する。 //メモリの位置はnewが返してくれるので、ポインタに入れておく。 Product* p = new Pruduct; //本来ならば、(*p).Disp()のような形でアクセスしなければならな…
http://www.idea-tech.net/index.htm こちらを参考にしました。 問題は、 八百屋さん計算システムを以下の仕様とガイドラインにしたがって コマンドライン・アプリケーションとして設計してください。 仕様: りんご、バナナ、トマト(野菜)、にんじんが商…
オブジェクト生成 CBook HarryPotter( "ハリーポッター賢者の石", "J.K.ローリング",1900, 52, 0 ); 範囲は、"{"から、"}"で囲まれる範囲で。動的オブジェクト生成 CBook* pHarryPotter = new CBook( "ハリーポッター賢者の石", "J.K.ローリング",1900, …
アップキャスト キャストする時、派生クラスのオブジェクトは基底クラスへの参照に渡すことができる。 継承木の上の方にあるクラスへのキャストなので、アップキャストという。 protectedアクセス指定子 protected:指定すると、それ以降のメンバは、外部には…