Thread: nested classes...

  1. #1
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459

    nested classes...

    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!
    hasafraggin shizigishin oppashigger...

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    nested classes? you mean a huge inheritance tree?

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

    Oskilian

  3. #3
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    is it bad to use classes solely fro the sake of organizing functions? is there an alternative?
    You could use namespaces.
    zen

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    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...]
    hasafraggin shizigishin oppashigger...

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you don't want to use objects and just want some system of grouping functions you could do this -

    Code:
    #include <cstdio>
    
    namespace ns
    {
    	void foo()
    	{
    		printf("Hello, ");
    	}
    
    	void bar()
    	{
    		printf("World!\n");
    	}
    
    }
    
    
    int main()
    {
    	
    	ns::foo();
    	ns::bar();
    
    	return 0;
    
    }
    'this' is a pointer to the current object, and is used within the member functions to refer to the current object.
    zen

  6. #6
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    the this keyword is used when pointing to this instance of something or this function... umm... look at this code:

    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;
     }
     private:
     int var1, var2;
    }
    ...that's one way it can be used.

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    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...
    hasafraggin shizigishin oppashigger...

  8. #8
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    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.
    zen

  9. #9
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >pre-fixing

    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!!!
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone with a spare java class file(s) with nested classes?
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-29-2009, 08:33 PM
  2. Problem with nested classes
    By Bargi in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 05:52 AM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  4. nested classes
    By vaibhav in forum C++ Programming
    Replies: 8
    Last Post: 09-27-2005, 07:51 AM
  5. Nested Classes
    By manofsteel972 in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2004, 11:57 AM