By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,122 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,122 IT Pros & Developers. It's quick & easy.

nested classes and multiple files

P: n/a
I have a (largish) "master" header file (>130 loc). I also have a number
of seperate "satelite" header files which declare various objects used
by the object declared in the "master" header file. In a clean design,
these "satelite" objects (i.e. declared in the satellite header files),
should really be nested classes within the master file.

However, if I was to put all the declarations in one massive file, it
will easily exceed 1000 lines in the one header file.

My question is that is the anyway that I can change these satilite
object declarations into nested class declarations (I tried
MasterClass::myClass {...}; but the compiler complained that MyClass was
not a member of MasterClass - that makes sense anyway). Long story short
- can I maintain the satellite (smaller) header files and one master
header file, whilst changing the satellite objcet declarations to nested
classes (nested within the master class).

Any help will be much appreciated. MTIA

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Alfonso Morra wrote:
[..]
My question is that is the anyway that I can change these satilite
object declarations into nested class declarations [..]


Well, yes. You can declare the nested class in the main class definition
and then define it later, say, in a separate header:

---------------------- outer.h
class outer {
public:
class inner;
};
---------------------- inner.h
class outer::inner {
int a;
};
---------------------- main.cpp
#include "outer.h"
#include "inner.h"

int main() {
outer o;
outer::inner oi;
}
----------------------------------

V
Jul 23 '05 #2

P: n/a


Victor Bazarov wrote:
Alfonso Morra wrote:
[..]
My question is that is the anyway that I can change these satilite
object declarations into nested class declarations [..]

Well, yes. You can declare the nested class in the main class definition
and then define it later, say, in a separate header:

---------------------- outer.h
class outer {
public:
class inner;
};
---------------------- inner.h
class outer::inner {
int a;
};
---------------------- main.cpp
#include "outer.h"
#include "inner.h"

int main() {
outer o;
outer::inner oi;
}
----------------------------------

V


Many Thanks Victor

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.