Without knowing what specific error it is that you're getting, the best I could tell you is that if the error is simply a notification that the program has crashed, (a runtime error) you should make sure the loops are not accessing an index of the arrays that does not exist.
Since you can't compile this code into an executable (where's the main() function?) and so we don't know what might happen when you run code we don't have, it's hard to help.
In setMatrix you don't deallocate memory before allocating new memory, causing a memory leak.