Skip to main content
gamedev.net
🔒 Locked

Class question

Started by PhireBat Jul 8, 2004 at 2:00 PM 1 replies 700+ views
Original Post
PhireBat
PhireBat
ok its probably a silly silly question but ive spent the last few hours trying to solve it ill try to illustrate this as easily as possible to make it clear: ive got a program with a window.cpp and a window.h to handle the win32 stuff, and main.cpp with the init(), think(), render() and shutdown() functions. all the modules (scripts, models, files etc) have their own header files with the classes and their member functions/variables, and *.cpp files to go with each header file containing the bodies of the functions. all the header files link to one standalone header with all the windows, opengl, string and other microsoft header files (common.h) ----------- Application ----------- window.cpp window.h main.cpp = COMMON.H = #if !defined H_COMMON #include #include "model.h" #endif = MODEL.H = class cModel { public: void Draw(); private: char name[256]; }; --------------------------- Generic Module = HEADER FILE = (example.h) --------------------------- #include "common.h" class cExample { public: void function(); cModel Model; <-------- error generated here private: int variable; }; ----------------------------- = SOURCE FILE = (example.cpp) ----------------------------- #include "example.h" void cExample::function() { variable = 1; }; ----------------------------- this generates C2079 - 'Model' uses undefined class 'cModel' ive tried putting the classes in the source file then just putting "class cModel" in the header file MODEL.H, and ive definatly included ALL the right files; i also get the same problem when i try to test the example class in MAIN.CPP, i can even declare the class exists right before declaring a class (if you get my drift) and it doesnt work? (in example.cpp) class cExample; cExample test; this generates - error C2079: 'test' uses undefined class 'cExample' Help!!!!! ta much - pez
felisandria
felisandria
Do you have a model.cpp?
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
NoahAdler
NoahAdler
Trichotillomania Learning Center

edit: d'oh, you changed the topic title, I guess this doesn't make as much sense now :-P

But seriously, do you have include guards in your headers? Something like:

#ifndef MYCLASS_HEADER#define MYCLASS_HEADER#include "whatever.hpp"class MyClass{  ...};#endif


This prevents the class from being included more than once, so it doesn't get re-included ad-infinitum.

If that isn't the problem, just make sure you actually are including the header which you're trying to make use of (e.g., put #include "example.h" in your example.cpp).

Hope this helps.
-bodisiw

Topic Locked

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

Sign in to reply to this topic.