1

guys, I have a question, I don't know how can I connect many headers in one header, let's call it "Master header" and use functions from that headers, for example

// A.h
#include <iostream>

class A {
public:
  A();
  void showMessage(string msg);
};

// B.h
class B {
public:
  B();
  void CountMessages()
};

// C.h
#include "A.h"
#include "B.h"

class C : public B, public A {
public:
  C();
  void DoSomething();
}

and I want to call function CountMessages from class 'b' using a class an object of class 'c' and/or a class 'a', like

//c.cpp
#include "C.h"
#include "B.h"    
#include "A.h"

extern A b_obj;
extern B a_obj;

C::DoSomething() {
  b_obj.CountMessages();
  a_obj.showMessage("Hello");
}
  • possible duplicate of [C++ class forward declaration](http://stackoverflow.com/questions/9119236/c-class-forward-declaration) – deviantfan Jan 18 '15 at 19:00

1 Answers1

1

I have a question, I don't know how can I connect many headers in one header, let's call it "Master header" and use functions from that headers,

Create the file and add #include lines for all the other header files.

MasterHeader.h:

#include "A.h"
#include "B.h"
#include "C.h"

c.cpp:

#include "MasterHeader.h"

Caution: I wouldn't recommend this practice in general. This is useful only if the interface provided by "MasterHeader.h" is primary, with "A.h","B.h", and"C.h" serving the purpose of ease of maintenance.

R Sahu
  • 204,454
  • 14
  • 159
  • 270