#ifndef ALGORITMI_MATRICE_H
#define ALGORITMI_MATRICE_H
class Matrice {
public:
Matrice (int nc = 0,
int nr = 0,
int **matrix = nullptr);
~Matrice ();
int rotazioneMatrice(char selettore, int indice, char direzione, int posizioni);
private:
int _nc;
int _nr;
int **_matrix;
};
#endif //ALGORITMI_MATRICE_H
#include "Matrice.h"
#include <cstring>
#include <iostream>
using namespace std;
Matrice::Matrice(int nc, int nr, int **matrix) {
_matrix = matrix;
_nc = nc;
_nr = nr;
}
Matrice::~Matrice() {
if(_matrix != nullptr) {
delete[] _matrix;
}
}
#include <iostream>
#include "Matrice.h"
#include "Matrice.cpp"
#include <fstream>
#define ERROR_PARAMETERS -1
#define NO_MEM -2
using namespace std;
int main (int argc, char * argv[]) {
int nr, nc;
int **matrix;
matrix = nullptr;
if(argc != 2){
cerr << "Errore nei parametri" << endl;
return ERROR_PARAMETERS;
}
ifstream file(argv[1]);
if(!file.is_open()) {
cerr << "Error while opening file.txt: No such file." << endl;
exit(1);
}
file >> nr >> nc ;
*matrix = new (nothrow) int [nr*nc];
if (*matrix == NULL) {
cerr << "Non è stato possibile allocare " << nr*nc << " elementi" << endl;
return NO_MEM;
}
while (file) {
for (int i = 0; i < nr; i++) {
for (int j = 0; j < nc; j++)
file >> matrix[i][j];
}
}
Matrice matx(nr, nc, matrix);
return 0;
}
Salve, ho definito il codice e la classe matrice in questa maniera, ma mi esce questo errore di compilazione:
Scanning dependencies of target Prova
[ 33%] Building CXX object CMakeFiles/Prova.dir/Esercitazioni/Prova/main.cpp.obj
[ 66%] Linking CXX executable Prova.exe
CMakeFiles\Prova.dir/objects.a(Matrice.cpp.obj): In function `ZN7MatriceC2EiiPPi':
C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:11: multiple definition of `Matrice::Matrice(int, int, int**)'
CMakeFiles\Prova.dir/objects.a(main.cpp.obj):C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:11: first defined here
CMakeFiles\Prova.dir/objects.a(Matrice.cpp.obj): In function `ZN7MatriceC2EiiPPi':
C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:11: multiple definition of `Matrice::Matrice(int, int, int**)'
CMakeFiles\Prova.dir/objects.a(main.cpp.obj):C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:11: first defined here
CMakeFiles\Prova.dir/objects.a(Matrice.cpp.obj): In function `ZN7MatriceD2Ev':
C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:18: multiple definition of `Matrice::~Matrice()'
CMakeFiles\Prova.dir/objects.a(main.cpp.obj):C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:18: first defined here
CMakeFiles\Prova.dir/objects.a(Matrice.cpp.obj): In function `ZN7MatriceD2Ev':
C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:18: multiple definition of `Matrice::~Matrice()'
CMakeFiles\Prova.dir/objects.a(main.cpp.obj):C:/Users/Giuse/CLionProjects/Algoritmi/Esercitazioni/Prova/Matrice.cpp:18: first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\Prova.dir\build.make:109: Prova.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:374: CMakeFiles/Prova.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:381: CMakeFiles/Prova.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:253: Prova] Error 2
qualcuno sa dirmi cosa sbaglio?