Skip to main content
gamedev.net
🔒 Locked

VC++ linker problem

Started by Mister Stewart Jul 31, 2002 at 3:22 PM 2 replies 250+ views
Original Post
Mister Stewart
Mister Stewart
In my project I have two .cpp files: - class_gameobject.cpp: a class is defined here - main.cpp: the main file, where winmain is. Now, I''ve included these two files into my project, and declared a gameobject object, guinea_peeg in main.cpp. class_gameobject.cpp compiles fine, but main.cpp does not seem to recognise the class - it keeps throwing errors where guinea_peeg is declared. I''ve obviously missed something, but since I''m still learning on my own, I would like some guidance. Can NE1 help? "Sweetie! Get Mommy''s bazooka!"
"16 days?? that's almost two weeks!!" Tucker
FiveFootFreak
FiveFootFreak
Have you programmed C++ before? Every class source file (the implementation of the class) requires a class header file (the definition of the class)

This is how the header file of a sample MyClass.h should look like:

#if !defined (MY_CLASS_INCLUDED)
#define (MY_CLASS_INCLUDED)

class MyClass
{
public:
MyClass(); //Constructor
virtual ~MyClass(); //Destructor
Dothis();
Dothat();
int GiveMeAnInt();

private:
bool APrivateVariable;
};

#endif

You then have to:
#include "MyClass.h"

somewhere at the top of your main.cpp

If this is all new to you, I suggest you read some beginners C++ tutorials, which are all over the net.
jakar
jakar
Near the top of you main.cpp, do you have [#include "class_gameobject.h"]?

[edited by - jakar on July 31, 2002 4:34:52 PM]
Mister Stewart
Mister Stewart
I was going to try that today in fact. Whilst I have programmed with C++ before, I always used to put everything in the one .cpp file. I know that this wasn''t very good practice, and I had read that when programming classes, you SHOULD have a header file and a .cpp file. But I didn''t realise that you HAD to do it this way. Like I said, I''m still learning.

Thanks a lot.

"Sweetie! Get Mommy''s bazooka!"
"16 days?? that's almost two weeks!!" Tucker

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.