Hello everyone. I writed a program to multiply a matrix with a vector using operator*. When I compiled this program, it did not run completely. This warning is: " Fault: access violation at 0x4011ca: write of address 0x40b804" or contructor function " vector::vector(float *)". I don't know why. I hope anybody help me, figure out for me. I really thank for help!
The segmentation fault happens on line 137, which calls the function on line 106, which (on line 116), calls the constructor on line 37 which assigns to v[i] on line 40, which HAS NOT BEEN ALLOCATED, with a 'new'.
The vector(a) will exist at that point, and have it's float *v member variable, which will point somewhere random, as it has not been initialized. When v[i] gets assigned on line 40, it will cause the segmentation fault. ie the program write somewhere it should not.
Well, I do have to ask- is this for an assignment, practice, or just the general desire to get a functional matrix class up and running?
As for the problem, just do as you did in the default constructor- make v a new float of size n, where n is the size of... well, you can figure that part out.
Other problems are:
(1) memory leak at line 108.
(2) int matrix::n=0;staticint &Size() {return n;}; This is truly awful. Only one matrix size can be used in the application, and it must match the vector size.
It is probably better to throw the code away, and start again.