Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Visual C++ and include order.

Reply
Thread Tools

Visual C++ and include order.

 
 
Holden
Guest
Posts: n/a
 
      09-15-2003
Hello,
I am using Visual C++ 6.0 with Service Pack 5 installed and I have run
into a problem that I haven't been able to figure out. I have written
two classes and I want them to have pointers to each other. So class
One has a private class variable of type Two and class Two has a
private class variable of type One. I #include the header file of the
other class in each file. When I try to build the project it gives me
three errors, all in regards to the line that the variable is declared
(ex: 'One' : missing storage-class or type specifiers). If I change
the order that the classes are included in Main.cpp from:
#include "One.h"
#include "Two.h"

to:
#include "Two.h"
#include "One.h"

then I get errors on the opposite classes (ex: 'Two' : missing
storage-class or type specifiers).
Is this something that I can't do in C++? Is there a problem with
Visual C++? Do I need to change my code or a setting somewhere?
Thanks in advance,
Holden.
 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      09-15-2003
Holden wrote:
> Hello,
> I am using Visual C++ 6.0 with Service Pack 5 installed and I have run
> into a problem that I haven't been able to figure out. I have written
> two classes and I want them to have pointers to each other. So class
> One has a private class variable of type Two and class Two has a
> private class variable of type One. I #include the header file of the
> other class in each file. When I try to build the project it gives me
> three errors, all in regards to the line that the variable is declared
> (ex: 'One' : missing storage-class or type specifiers). If I change
> the order that the classes are included in Main.cpp from:
> #include "One.h"
> #include "Two.h"
>
> to:
> #include "Two.h"
> #include "One.h"
>
> then I get errors on the opposite classes (ex: 'Two' : missing
> storage-class or type specifiers).
> Is this something that I can't do in C++? Is there a problem with
> Visual C++? Do I need to change my code or a setting somewhere?
> Thanks in advance,
> Holden.


You can forward declare the other class ...

// file one.h
class B; // incomplete class decl.

class A
{
public:
B * b;

};


// file two.h
class A; // incomplete class decl

class B
{
public:
A * a;
};


It won't matter which order they are included.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Include and Include File Gregory A. Beamer ASP .Net 2 07-28-2009 09:20 PM
Re: Include and Include File sloan ASP .Net 0 07-28-2009 08:18 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
what's the difference between #include "queue.h" and #include "queue.cpp" Kceiw C++ 3 03-14-2006 03:01 AM
When to use #include <> and #include " " Tuckers C++ 18 05-18-2005 08:42 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57