Jump to content
  • Advertisement

Archived

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

colinisinhere

Class pre-definition?

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

You know how with functions, you can ''pre-define'' them? example:
void fart(int gas_desity);

void main()
{
    for(int i = 0; i < 10000; i++) fart();
}

void fart(int gas_desity)
{
//...blah

}
Well i need to do somthing like this with classes but i dont think its possible; its somthing like this: #include "main.h" <-Define my class ''player'' #include "weapons.h" <-Use class ''player'' #include "player.h" <-^needs to use weapon.h''s functions!^ please help!

Share this post


Link to post
Share on other sites
Advertisement
What you call a "pre-definition" is known as a declaration .
A type that has been declared but not defined is known as an incomplete type .

Example of class declaration : class player;

An incomplete type can be used as

  • Parameter or return type in a function declaration : player foo( player f );
  • As the associated type of a pointer or reference : player* foo;


However, you cannot create an actual instance of the type (variable, value member) until the type is fully defined, as its size is not known. There is no way around that, but there is a lot you can already do with a pointer to an incomplete type.

e.g. Bridge pattern / Pointer-to-implementation (pimpl) idiom.




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on September 21, 2003 12:16:19 AM]

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!