class declaration?

T

thomas

for the following two files, it has a problem of recursive inclusion.
Is there a mechanism like class declaration to solve the problem?

---header1.h---
#include "header2.h"

class class1{
public:
void method1(class2 &ins);
};

--header2.h---
#include "header1.h"

class class2{
class1 *ptr;
public:
...
};
 
L

lnitzu

for the following two files, it has a problem of recursive inclusion.
Is there a mechanism like class declaration to solve the problem?

---header1.h---
#include "header2.h"

class class1{
public:
void method1(class2 &ins);

};

--header2.h---
#include "header1.h"

class class2{
class1 *ptr;
public:
...

};

I think you need to use guard regions

#ifndef _XXX
#define _XXX

#include .....
....
#endif
 
H

Harish

for the following two files, it has a problem of recursive inclusion.
Is there a mechanism like class declaration to solve the problem?

---header1.h---
#include "header2.h"

class class1{
public:
void method1(class2 &ins);

};

--header2.h---
#include "header1.h"

class class2{
class1 *ptr;
public:
...

};

You can use a forward declaration in both header files
 
J

Juha Nieminen

thomas said:
for the following two files, it has a problem of recursive inclusion.
Is there a mechanism like class declaration to solve the problem?

---header1.h---
#include "header2.h"

class class1{
public:
void method1(class2 &ins);
};

---header1.h---
class class2;

class class1{
public:
void method1(class2 &ins);
};
--header2.h---
#include "header1.h"

class class2{
class1 *ptr;
public:
...
};

--header2.h---
class class1;

class class2{
class1 *ptr;
public:
...
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top