quick question on external classes
#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
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.
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
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
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.
// 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement