Sign in to follow this  
PhireBat

Class question

Recommended Posts

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 <windows.h> #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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this