I apologise for what I'm pretty sure is a fairly stupid question, but I can't get it to work!
I'm also not sure what information is too much information so I probably won't give enough info so sorry for that too - just ask.
I began writing a class within main.cpp, and it got large so I decided to shift it to a different source file. I'm not too sure on how to do this, and can't figure anything to help fix this specific problem from internet resources (hence the asking).
I started off with the class definition including all of the function definitions above the main program function. This runs fine. I then split this up into two separate pieces. The class declaration (I think that's the correct term) above the main function and the function definitions below the main function.
This also runs perfectly well. I proceeded to cut the class declaration out into a header file. This header file is of the form
#ifndef INC_MATRIX_H
#define INC_MATRIX_H
class matrix{
//ETC
};
#endif
Which I have read somewhere is useful but I'm not entirely sure why, I think it's to stop redeclaration of the functions if the header is included more than once.
So currently we have this header file included along with the other includes. Then the main function and then the function definitions beneath the main function. This also compiles and runs perfectly well.
The next step I took was to cut the function definitions into their own separate .cpp file. The only addition that was made to this .cpp file was that some extra includes had to be added to the top (specifically iostream and cstdlib). ALSO the matrix.h file was included.
In this configuration Dev-C++ brings up linker errors when I try to compile and run the code. Specifically they are of the form
[Linker Error] undefined reference to
matrix <bool>::matrix(int, int)
And the code doesn't run (obviously). how can I fix this? Thanks in advance.
Edit: It's been discovered that this is due to the fact that it's a templated class and in the scope of the matrix.cpp file the template isn't introduced to the bool type. I now want to figure out how to fix this without adding lots of lines of code to individually make each function accept each given type. Oh, and I appreciate that I can define the functions in the header. But I thought that we weren't meant to do that? I thought the idea was that you simply include the declaration.