Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,338 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,823 people online right now. Registration is fast and FREE... Join Now!




Avoiding nested includes

 
Reply to this topicStart new topic

Avoiding nested includes

Glasseater
post 15 Mar, 2008 - 01:42 PM
Post #1


New D.I.C Head

*
Joined: 15 Jun, 2007
Posts: 46


My Contributions


I have a few header files (one has type definition, the others contain classes). The problem is that I want to be able to include a basic header that will have all my definitions, classes, etc with one line (the include). For example, something like this;

cpp

#include "myheader.h"

int main()
{
MyClass c;
//... some code here
}


cpp

#ifndef _MYHEADER_
#define _MYHEADER_


typedef std::vector<sometype> MyType;

//this is the problem
#include "myclassdef.h"


#endif //_MYHEADER_


cpp

#ifndef _MYCLASSDEF_
#define _MYCLASSDEF_


//this is the problem
#include "myheader.h"

//my class requires one of the typedefs
class MyClass
{
MyType myvar; // <-- this is what uses the typedef
//... some definitions
}


#endif


But if I need the typedef in "myclassdef.h" then it makes me include "myheader.h" within "myclassdef.h". Here's where the problem starts.. anything in "myheader.h" gets redeclared (obviously).

So how do do my definitions (specifically the typedef) and be able to include my classes within the header. Can extern be used on typedefs?

Thanks for any advice.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/19/08 03:30PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month