View Full Version : nested classes...

12-09-2001, 01:19 AM
i have a sequence of nested classes... is it bad to use classes solely fro the sake of organizing functions? is there an alternative? what i do is declare an instance of the class before the function definitions... so that the class [nested] functions can call the functions in the instance of itself...

y'know, i might just reprogram all of it, it's getting kinda heavy!

12-09-2001, 01:28 AM
nested classes? you mean a huge inheritance tree?

if so, I agree with it, as long as you keep it under control


12-09-2001, 10:02 AM
is it bad to use classes solely fro the sake of organizing functions? is there an alternative?

You could use namespaces.

12-09-2001, 10:45 AM
what are those? and... what's the point of this... [i mean, the keyword 'this', not this post, as that's clearly defined above...] thanks...

i am starting to redesign my nested classes... and it's not inheritance since no class has copies of other class' functions... it's just including the declaration of all classes, and organizing instances of them in each other... [not recursively, of course...]

12-09-2001, 11:15 AM
If you don't want to use objects and just want some system of grouping functions you could do this -

#include <cstdio>

namespace ns
void foo()
printf("Hello, ");

void bar()


int main()


return 0;


'this' is a pointer to the current object, and is used within the member functions to refer to the current object.

12-09-2001, 11:36 AM
the this keyword is used when pointing to this instance of something or this function... umm... look at this code:

class c1
c1(int var1, int var2)
// These assignments assign the value of the arguement to the value of this object's field (or member).
var1 = this.var1;
var2 = this.var2;
int var1, var2;

...that's one way it can be used.

12-09-2001, 11:46 AM
heeeey!!! lol, i wish i knew that before!!! well i still need to organize data variables... can i use namespace for that as well? can i nest them? [i might do so...] and... is this a standard keyword? i couldn't find it in my bc45 help file...

thanks a lot...

12-09-2001, 11:57 AM
Yes, yes and yes but they are one of the newer additions so may not be supported in older compilers.

They're just a convience, though. There's nothing stopping you pre-fixing function and variable names with some identifying name.

12-09-2001, 04:25 PM

yes... thanks, that does occur to me... but i figured that was what classes were for... as a means of organizing a programmer's project... in that case i would not see any reason why we'd have namespaces... other than that they would allocated concrete variables instead of creating templates for them [as classes do...] great! say... is it very unusual to have a function of one class call a function of another class? i'd say this is good, except that i have to seperate the class definitions from the class function definitions in order to link to it... [which is a peeve since i have many a file that just have the class definitions and many a seperate file for the function include tree... argh!!!