witam,
piszę klasę, która będzie obsługiwać macierze i zapisywać je jako 2 wymiarowe dynamiczne alokowane macierze, ale nie wiem dlaczego dostaję błędy, poniżej załączam kod i błędy
matrix.h
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <glut.h>
using namespace std;
class Matrix
{
public:
Matrix();
Matrix(int size);
~Matrix();
private:
float **arr;
unsigned size;
};
#endif
matrix.cpp
#include "matrix.h"
Matrix::Matrix()
{
this->size = 3; // default size = 3
this->arr = new float * [this->size];
for ( unsigned i = 0 ; i < this->size ; ++i)
this->arr[i] = new float [ this->size ];
}
Matrix::Matrix(int size)
{
this->size = size;
this->arr = new float * [this->size];
for ( unsigned i = 0 ; i < this->size ; ++i)
this->arr[i] = new float [ this->size ];
}
Matrix::~Matrix()
{
for ( unsigned i = 0 ; i < this->size ; ++i)
delete [] this->arr[i];
delete [] this->arr;
}
i błędy
Error 1 error LNK2005: "public: __thiscall Matrix::~Matrix(void)" (??1Matrix@@QAE@XZ) already defined in mathDemo.obj ...\mymath\mathDemo\mymath.lib(matrix.obj)
Error 2 error LNK1169: one or more multiply defined symbols found D:\Erasmus\301CR\porfolio\mymath\Debug\mathDemo.exe 1
wszystko sie kompiluje dopóki nie dodam np.
Matrix m();
cout << m;
lub
Matrix m(3);
wtedy się wysypuje.