![]() |
.H or .cpp?
I have a class called Monster, now what I have is an array of 5 monsters, because there are 5 different monsters in my program.
:
Monster array[5];I know that is horrible code, mine doesn't actually look like that though. I am just wondering, if you are only using the file to set the data members for the array, should I use a .cpp file or a header? I'm thinking a .cpp file is the way to go, but I am also under the impression you should do "#include "array.cpp"" type declarations, so I would need a header in association to simply refer to that .cpp file. EDIT: Or, would I just set each value for each array in the Monster.cpp file, which holds all the member functions? |
That would go in a .cpp file since you are calling functions and performing an action. Make some sort of initialization function and put the code there.
|
Never #include a .cpp file. The reasons and pros and cons and all have been covered on this forum several times.
|
If you want to have some array outside of your file you should use the keyword extern. I'll repeat what DaWei said: Never include a .cpp file, always use header files and add:
:
#ifndef FILENAME_H |
| All times are GMT -5. The time now is 11:45 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC