Namratha
Namratha

Reputation: 16780

how to declare a member of a class type defined in a different file

I have a header file in which I have defined a struct. I want an instance of this struct to be a member of a class that is defined in a different file. How do I do it?

Upvotes: 0

Views: 257

Answers (1)

Erik
Erik

Reputation: 91270

#include the header containing the struct in the header where you define the class.

Foo.h:

struct Foo {
};

Bar.h:

#include "Foo.h"
class Bar {
  Foo f;
};

Upvotes: 9

Related Questions