I'm studying C++ and now I started implementing a code to solve some numerical methods.
I created a Matrix class (2D with contiguous memory allocation) and I'm using it in some functions. However, the class which uses the Matrix class provides an array with the first element zero. I suppose it is an array decay problem.
but the GaussLegendrePoints points(9) returns:
0 0.166667 0.166667
0.666667 0.166667 0
0.166667 0.666667
The GaussLegendrePoints points(9) calls the function GaussLegendrePoints::triangleThreePointsInside() which has the same code shown in the beginning.
As I did not manage to find the problem, I was wondering if someone in the forum could help.
Furthermore, as I don't have experience with C++ any comment about how to improve the code is very welcome.
problems in Matrix.cpp
- your default constructor creates a 0x0 matrix, but Matrix_alloc tries to access mat[0]
- you are missing a proper copy constructor and assignment operator, and there are errors in your destructor
I would suggest you to use std::vector instead, .data() will give you a pointer if you needed for an external library
(will have to add a operator() to access in mat(r, c) fashion)
(not fixed)
your makefile is not detecting the dependencies correctly
for example, a change in Matrix.h should send main.cpp to recompile
also, Matrix.cpp contains template code, but it is compiled and procudes an empty object file (Matrix.o)
thank you very much for the help. I understood the problems in my code.
Regarding the make, I found an automated one on internet, but it dos not detect the .h files dependencies and I did not manage to modify it. I really would appreciate if you could take a look on that.
also, you should simply move the templates implementation from Matrix.cpp to Matrix.h
if you want them to be in separate files you may just #include "Matrix.impl" at the end
It seems to be working properly, but it generates some dependencies with strange paths, like src/../include/Messages.h
Is that correct? You can check the project in the GitHub link.
> src/../include/Messages.h
I guess that you've got that because your includes are of the form #include "../include/Messages.h"
the path will resolve correctly, so I don't think that's an issue