whats going on ? am struggling i get this far code compiles and runs on Dev C++ but gives me 23 warnings no errors and Make fail on boreland C++? eg "fuction containing for are not inline, what...[TRUNCATED by being used as subject - OriginalGriff
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define PAUSE {printf("Press \"Enter\" to continue\n"); fflush(stdin); getchar(); fflush(stdin);}
class Matrix;
double Det(const Matrix& a);
Matrix Diag(const int n);
Matrix Diag(const Matrix& v);
Matrix Inv(const Matrix& a);
Matrix Ones(const int rows, const int cols);
int Size(const Matrix& a, const int i);
Matrix Zeros(const int rows, const int cols);
class Exception
{
public:
const char* msg;
Exception(const char* arg)
: msg(arg)
{
}
};
class Matrix
{
public:
Matrix()
{
p = NULL;
rows = 0;
cols = 0;
}
Matrix(const int row_count, const int column_count)
{
p = NULL;
if (row_count > 0 && column_count > 0)
{
rows = row_count;
cols = column_count;
p = new double*[rows];
for (int r = 0; r < rows; r++)
{
p[r] = new double[cols];
for (int c = 0; c < cols; c++)
{
p[r][c] = 0;
}
}
}
}
Matrix(const Matrix& a)
{
rows = a.rows;
cols = a.cols;
p = new double*[a.rows];
for (int r = 0; r < a.rows; r++)
{
p[r] = new double[a.cols];
for (int c = 0; c < a.cols; c++)
{
p[r][c] = a.p[r][c];
}
}
}
double& operator()(const int r, const int c)
{
if (p != NULL && r > 0 && r <= rows && c > 0 && c <= cols)
{
return p[r-1][c-1];
}
else
{
throw Exception("Subscript out of range");
}
}
double get(const int r, const int c) const
{
if (p != NULL && r > 0 && r <= rows && c > 0 && c <= cols)
{
return p[r-1][c-1];
}
else
{
throw Exception("Subscript out of range");
}
}
Matrix& operator= (const Matrix& a)
{
rows = a.rows;
cols = a.cols;
p = new double*[a.rows];
for (int r = 0; r < a.rows; r++)
{
p[r] = new double[a.cols];
for (int c = 0; c < a.cols; c++)
{
p[r][c] = a.p[r][c];
}
}
return *this;
}
Matrix& Add(const double v)
{
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
p[r][c] += v;
}
}
return *this;
}
Matrix& Subtract(const double v)
{
return Add(-v);
}
Matrix& Multiply(const double v)
{
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
p[r][c] *= v;
}
}
return *this;
}
Matrix& Divide(const double v)
{
return Multiply(1/v);
}
friend Matrix operator+(const Matrix& a, const Matrix& b)
{
if (a.rows == b.rows && a.cols == b.cols)
{
Matrix res(a.rows, a.cols);
for (int r = 0; r < a.rows; r++)
{
for (int c = 0; c < a.cols; c++)
{
res.p[r][c] = a.p[r][c] + b.p[r][c];
}
}
return res;
}
else
{
throw Exception("Dimensions does not match");
}
return Matrix();
}
friend Matrix operator+ (const Matrix& a, const double b)
{
Matrix res = a;
res.Add(b);
return res;
}
friend Matrix operator+ (const double b, const Matrix& a)
{
Matrix res = a;
res.Add(b);
return res;
}
friend Matrix operator- (const Matrix& a, const Matrix& b)
{
if (a.rows == b.rows && a.cols == b.cols)
{
Matrix res(a.rows, a.cols);
for (int r = 0; r < a.rows; r++)
{
for (int c = 0; c < a.cols; c++)
{
res.p[r][c] = a.p[r][c] - b.p[r][c];
}
}
return res;
}
else
{
throw Exception("Dimensions does not match");
}
return Matrix();
}
friend Matrix operator- (const Matrix& a, const double b)
{
Matrix res = a;
res.Subtract(b);
return res;
}
friend Matrix operator- (const double b, const Matrix& a)
{
Matrix res = -a;
res.Add(b);
return res;
}
friend Matrix operator- (const Matrix& a)
{
Matrix res(a.rows, a.cols);
for (int r = 0; r < a.rows; r++)
{
for (int c = 0; c < a.cols; c++)
{
res.p[r][c] = -a.p[r][c];
}
}
return res;
}
friend Matrix operator* (const Matrix& a, const Matrix& b)
{
if (a.cols == b.rows)
{
Matrix res(a.rows, b.cols);
for (int r = 0; r < a.rows; r++)
{
for (int c_res = 0; c_res < b.cols; c_res++)
{
for (int c = 0; c < a.cols; c++)
{
res.p[r][c_res] += a.p[r][c] * b.p[c][c_res];
}
}
}
return res;
}
else
{
throw Exception("Dimensions does not match");
}
return Matrix();
}
friend Matrix operator* (const Matrix& a, const double b)
{
Matrix res = a;
res.Multiply(b);
return res;
}
friend Matrix operator* (const double b, const Matrix& a)
{
Matrix res = a;
[edit]Subject moved in to body - OriginalGriff[/edit]