I created a program in c ++ to manipulate arrays, and split the source code into 2 files, one with functions and the other with implementation, all functions work correctly, however when starting any function for the second time, regardless of whether it was the same one at a time or another, returns a segmentation float error, any function started by the 1 time works perfectly, I would like a help, thanks in advance.
// main.cpp
#include <iostream>
#include "func.cpp"
using namespace std;
int main()
{
matriz *m1 = criaMatriz(5,5);
atribuiMatriz(2,1,m1,45.4);
//cout << linhasMatriz(m1) << endl;
//cout << *(*((*m1).mat + 1)) << endl;
//cout << m1 << endl;
cout << acessaMatriz(2,1,m1) << endl;
//cout << m1 << endl;
cout << acessaMatriz(2,1,m1) << endl;
//cout << (*m1).lin << endl;
//cout << linhasMatriz(m1) << endl;
//liberaMatriz(m1);
return 0;
}
// func.cpp
Quote
#include <iostream>
using namespace std;
struct matriz
{
int lin;
int col;
double **mat;
}typedef matriz;
matriz* criaMatriz(int lin,int col)
{
matriz *a,b;
a = &b;
(*a).lin = lin;
(*a).col = col;
(*a).mat = new double*[lin];
for(int i = 0;i < lin;i++)
*((*a).mat + i) = new double[col];
//okokokokok
return a;
}
void liberaMatriz(matriz *a)
{
int lin = (*a).lin;
for(int i = 0;i < lin;i++)
delete[] *((*a).mat + i);
delete[] (*a).mat;
}
double acessaMatriz(int lin,int col,matriz *a)
{
return *(*((*a).mat + lin - 1) + col - 1);
}
void atribuiMatriz(int lin,int col,matriz *a,double comp)
{
*(*((*a).mat + lin - 1) + col - 1) = comp;
}
int linhasMatriz(matriz *a)
{
int lin = (*a).lin;
return lin;
}
int colunasMatriz(matriz *a)
{
return (*a).col;
}