Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

try_catch_this

quick question on external classes

This topic is 5520 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

#ifndef __MessageHandlers_H #define __MessageHandlers_H #include <windows.h> class C_WinMain; LRESULT KeyMessageHandler( C_WinMain*, WPARAM&, LPARAM& ); #endif class C_WinMain is defined in another file. How do I use it in MessageHandlers.h thanks

Share this post


Link to post
Share on other sites
Advertisement
In your header file, put extern before the variable. In one source file define it as a normal global variable. Make sure you initialize everything you need before trying to actually use it.

Share this post


Link to post
Share on other sites
Another quick question.

if you declare a class thats to be defined in another file
can you use any methods or properties from that class if you know what they are?

ok in one file you declare the class

class C_WinMain;

and you want to use the properity ToFullScreen in a function.

C_WinMain is defined else where.

Is there a way to do this

C_WinMain CMainWindow;
CMainWindow.Togglefullscreen = 0;

Without the compiler throwing an error.

its kinda like a partial definition of the class.

thanks

Share this post


Link to post
Share on other sites
You can''t use any class that aren''t actually defined, ever. So, if you only state

// classdef.h
class Foo;

in a header, and only include that header in another cpp file, you certainly can''t use any of its functions; the compiler has no idea whether they''re valid or not. So, you CAN''T:

// otherfile.cpp
#include "classdef.h"
void MyFunc() { Foo foo; }

Stating something like "class Foo;" with no definition is ONLY good for declaring a name you intend to define later, but need now. You can only declare pointers to that class until you define it at all:

// gratuitousexample.h
class Foo;

class Bar
{
Foo * m_pFoo; // must be a pointer
};

class Foo
{
};

The reason it has to be a pointer is because the compiler doesn''t have a definition for Foo, so it wouldn''t know how much memory to allocate for each instance of Bar. Since it''s a pointer, and those are always a specific size, it can do it.

So, basically, "class Foo;" is just for type safety. Don''t use it for convenience.

I like pie.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!