noconanのプロフィール

@noconan noconan
ありがとう数18
質問数27
回答数2
ベストアンサー数
0
ベストアンサー率
0%
お礼率
80%

  • 登録日2006/03/22
  • 自作の行列クラスを継承するさいにエラーがでます

    現在、c++の学習で、自作の基底行列クラスMatrixを作成し、このクラスを継承して新たにlduMatrixを作成する事を考えています。 が、継承し、 lduMatrix a( 3, 3); a = 3; とすると、 main.C:13: warning: passing ‘double’ for argument 1 to ‘lduMatrix::lduMatrix(int)’ というエラーがでてコンパイルできずにいます。その一方で、 lduMatrix a(3,3, 3.14); とするとコンパイルはとおり、lduMatrix行列の各要素(a[1][1]など)の値をプリントさせると、[[3.14]]の値が入っていることを確認しております。 どこが間違っているのか御指導いただけると幸いです。 以下、クラスの中身です。よろしくおねがいします。 《Class: Matrix》 #include <iostream> class Matrix{ private: //! Size of row and column in Matrix int row_, col_; //! Row pointers double** m_; //! Allocate function for row-pointers void allocate(); public: Matrix(); //! Constructor with given matrix size Matrix( const int, const int ); //! Constructor with given matrix size and value fro all elements Matrix( const int, const int, const double ); //! Destructor ~Matrix(); ・・・省略・・・ double* operator[]( const int ); double* operator[]( const int ) const ; void operator=( const double ); }; /* Private functions *********************************************** */ void Matrix::allocate() { m_ = new double* [row_]; m_[0] = new double [row_*col_]; for ( int i=1; i<row_; i++ ){ m_[i] = m_[i-1] + col_; } } /* Destructor ****************************************************** */ Matrix::~Matrix(){ delete[] m_[0]; delete[] m_; } /* Constructors **************************************************** */ // NULL constructor Matrix::Matrix() : row_(0), col_(0), m_(NULL) {} // Constructor with given matrix size Matrix::Matrix( const int row, const int col ) : row_(row), col_(col) { allocate(); } // Constructor with given matrix size and value for all elements Matrix::Matrix( const int row, const int col, const double s ): row_(row), col_(col) { allocate(); double* m = m_[0]; for ( int i=0; i<row_*col_; i++ ){ m[i] = s; } } 《省略》 /* Member operators ************************************************ */ double* Matrix::operator[]( const int i ){ return m_[i]; } void Matrix::operator=( const double t ){ double* m = m_[0]; int nm = row_*col_; for ( int i=0; i<nm; i++ ) { m[i] = t; } } 《Class: lduMatrix》 class lduMatrix : public Matrix{ public: lduMatrix(); lduMatrix( const int ); lduMatrix( const int, const double ); }; lduMatrix::lduMatrix() {} lduMatrix::lduMatrix( const int mSize ) : Matrix( mSize, mSize, 0.0 ) {} lduMatrix::lduMatrix( const int mSize, const double s ) : Matrix( mSize, mSize, s ) {}

  • 質問です!とても基本的なことなので、少し詳しい方なら、解ると思います。

    最近、VC++の勉強を始めました。 とあるサイトで勉強させていただいていて、 その中のプログラムで http://www.asahi-net.or.jp/~yf8k-kbys/newcpp9.html この、簡単なゲームを作るのがありました。 ほぼ理解できるのですが、1箇所理解できないのが、 Daimao bu; //対決場所にいる大魔王bu! Hero you; //対決場所にいるヒーローyou! ここです。ここでは自分で好きな変数型を作ってるという意味で daimaoという型(intとかみたいな)の変数名 buという事だと思うのですが、 daimao形と言われても、中に数字とか文字とか何が入るのでしょうか? どう解釈すればよいのでしょうか? そして、ここで、 bu と you を作ってあるためだと思うのですが、 この行の少し下に、 you.kougeki_suru(kougeki); //ヒーローyouの攻撃 というのもあります。 いきなりyou.でヒーローのクラスと継承できてる形になってますが、 どうしてでしょうか? 多分上に書いた、Hero youのおかげで書けるようになってると思うのですが、 詳しく教えていただけないでしょうか? よろしくお願いします。