Jump to content
  • Advertisement
Sign in to follow this  

Class question

This topic is 5068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:


#include "whatever.hpp"

class MyClass


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!