class 속에서 dynamically class 사용하기
다음과 같이 Matrix라는 class를 만들었습니다.  main에서  이를
변수로 잡아 실행시키면 잘 됩니다. 그러나 ClassB라는 곳에서
Matrix m(nx, ny) (여기서 nx와 ny는 input으로 하려고 합니다.)
을 만들려고 하면 컴파일 에라가 나옵니다.  고수님들 도와 주세요.
( 어 코드가 영 이상하게 나오네요. )
[code]
#include 
using namespace std;
class Matrix
{
public:
    double *data_;
    int     nx_, ny_;
    Matrix(int nx, int ny)
    {
        nx_    = nx;
        ny_    = ny;
        data_ = new double [nx*ny];
        // set the matrix as an identity matrix, in Fortran array format
        for(int i=0; i
                if( i==j)
                    data_[(i-1)+(j-1)*nx_] = 1;
                else
                    data_[(i-1)+(j-1)*nx_] = 0;
            }
    }
~Matrix() { cout
    double& operator()(int i, int j)
    {
        return data_[ (i-1)+(j-1)*nx_ ];
    }
};
class ClassB
{
public:
//Matrix m(nx,ny); 다.
    ClassB( int nx=10, int ny=10)
    {
        //m = new Matrix (nx, ny);  
    }
   ~ClassB()
    {
       //delete [] v;
    }
};
int main()
{
    //-------------------------
    //  Test Matrix Class
    //-------------------------
    int nx=3, ny=4;
    Matrix m1(nx,ny);
    for(int i=0; i
        for(int j=0; j
            cout 
        }
        cout 
    }
    //-------------------------
    //  Test of ClassB
    //-------------------------
//ClassB ms;
    return 0;
}
[/code]


Matrix *m; m = new
Matrix *m;
m = new Matrix(x,y);
아닌가요??
C++ 같은데 C++에서 new 는 생성된 인스턴스의 포인터를 반환 하는걸로 기억합니다
댓글 달기