A
atomik.fungus
Hi, im having problems compiling some code, and i dont understand why.
I've made a Matrix class for any kind of data and now im implementing
an inherited class with all the mathematical stuff (MMatrix)
(determinants and so on).
The data and the number of rows and columns are declared in the base
clase as protected. When i ask the functions of the inherited class to
use them, the compiler(g++) tells me that they haven't been declared in
that ambit( sorry for the poor translation but errors are in spanish).
Here is the code for the inherited class. (The base class works
perfectly )
The code for the constructors has been copy pasted from the base class
in a desperate try. Originally it wasnt there only the initialization
to 0 of the matrix but the problem eas the same.
#ifndef MMATRIX_CPP
#define MMATRIX_CPP
#include <iostream>
#include <cstdlib>
#include "matrix.cpp"
using namespace std;
//Definicion de la clases
template< class T >
class MMatrix : public Matrix< T > //Hereda de las matrices
{
public:
MMatrix( unsigned = 3, unsigned = 3 );
MMatrix( const MMatrix< T > & ); //Constructor de copia
};
#endif
/*mmatrix.hpp*/
#include "mmatrix.cpp"
#include <iostream>
#include <cstdlib>
using namespace std;
//Constructor para las nuevas matrices identico al otro
template< class T >
MMatrix< T >::MMatrix( unsigned rows, unsigned columns )
{
int i, j;
assert( rows > 0 );
assert( columns > 0 );
r_size = rows; //Si no se pasa el tamaño se asume 3
c_size = columns; //Si no se pasa el tamaño se asume 3
data = new T*[ rows ];
for( i = 0; i < rows; i++ )
data[ i ] = new T[ columns ];
assert( data != 0 );
for( i = 1; i <= r_size; i++ ) {
for( j = 1; j <= c_size; j++ ) This( i, j ) = 0;
}
}
template< class T >
MMatrix< T >::MMatrix( const MMatrix< T > &init ) : r_size( init.r_size
), c_size( init.c_size )
{
int i, j;
data = new T*[ r_size ];
for( i = 0; i < r_size; i++ )
data[ i ] = new T[ c_size ];
assert( data != 0 );
for( i = 0; i < r_size; i++ ) {
for( j = 0; j < c_size; j++ )
data[ i ][ j ] = init.data[ i ][ j ];
}
}
I also have some problem working with several files and the
preprocessor, but thats another problem.
Thanks.
P.D. "This" is a macro "#define This( i, j ) this->operator()( (i), (j)
)" in the base class archive
I've made a Matrix class for any kind of data and now im implementing
an inherited class with all the mathematical stuff (MMatrix)
(determinants and so on).
The data and the number of rows and columns are declared in the base
clase as protected. When i ask the functions of the inherited class to
use them, the compiler(g++) tells me that they haven't been declared in
that ambit( sorry for the poor translation but errors are in spanish).
Here is the code for the inherited class. (The base class works
perfectly )
The code for the constructors has been copy pasted from the base class
in a desperate try. Originally it wasnt there only the initialization
to 0 of the matrix but the problem eas the same.
#ifndef MMATRIX_CPP
#define MMATRIX_CPP
#include <iostream>
#include <cstdlib>
#include "matrix.cpp"
using namespace std;
//Definicion de la clases
template< class T >
class MMatrix : public Matrix< T > //Hereda de las matrices
{
public:
MMatrix( unsigned = 3, unsigned = 3 );
MMatrix( const MMatrix< T > & ); //Constructor de copia
};
#endif
/*mmatrix.hpp*/
#include "mmatrix.cpp"
#include <iostream>
#include <cstdlib>
using namespace std;
//Constructor para las nuevas matrices identico al otro
template< class T >
MMatrix< T >::MMatrix( unsigned rows, unsigned columns )
{
int i, j;
assert( rows > 0 );
assert( columns > 0 );
r_size = rows; //Si no se pasa el tamaño se asume 3
c_size = columns; //Si no se pasa el tamaño se asume 3
data = new T*[ rows ];
for( i = 0; i < rows; i++ )
data[ i ] = new T[ columns ];
assert( data != 0 );
for( i = 1; i <= r_size; i++ ) {
for( j = 1; j <= c_size; j++ ) This( i, j ) = 0;
}
}
template< class T >
MMatrix< T >::MMatrix( const MMatrix< T > &init ) : r_size( init.r_size
), c_size( init.c_size )
{
int i, j;
data = new T*[ r_size ];
for( i = 0; i < r_size; i++ )
data[ i ] = new T[ c_size ];
assert( data != 0 );
for( i = 0; i < r_size; i++ ) {
for( j = 0; j < c_size; j++ )
data[ i ][ j ] = init.data[ i ][ j ];
}
}
I also have some problem working with several files and the
preprocessor, but thats another problem.
Thanks.
P.D. "This" is a macro "#define This( i, j ) this->operator()( (i), (j)
)" in the base class archive