I've written a class that defines a Bow object with it's colour, number of arrows etc. and two actions, draw and fire. The actions draw the Bow back and fire it if it's drawn then assign a random number of points for the shot.
I put the declaration and definition into different files (declaration in header file, definition in .cpp) and am trying to use them with the #include directive in a test chassis to test all the functions but I'm recieving an error stating the file can't be accessed. Am I supposed to add the .h and .cpp files into the program? Can someone explain my error/point me towards a good guide for splitting classes into files for later use?
Also, in the definition I'm getting this error:
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Sorry for the length but wasn't sure what was necessary to put in so I put it all in.
You also need to compile the two .cpp files together, i.e. command [options] Bow.cpp test.cpp, or add the missing one to the project's list of source files... this is very different in all IDE's so that's up to you to figure out.
But if you have any classses with .cpp "definition" files, they needs to be linked against, usually, in the way that I specified above..
On a side note adding #include <iostream> to both class definition and header is not necessary. once the preprocessor includes the header, it includes all headers defined within.
So typically I have all my #includes in my header file.
Then in the .cpp class definition simply:
1 2 3 4 5 6
#include "header.h"
// and namespaces
using std::cout;
using std::string;
using std::endl;