Nested structures

This is a discussion on Nested structures within the C++ Programming forums, part of the General Programming Boards category; Alright I was wondering how do you use nested structures... Code: //This is the struct for our CHARACTER abilities and ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    Nested structures

    Alright I was wondering how do you use nested structures...

    Code:
    //This is the struct for our CHARACTER abilities and what not
    struct CHARACTER
    {
    	COORD pos;  //Coordinates of the position of our CHARACTER
     
    	unsigned char dispChar; // The ASCII representation of the CHARACTER
    	unsigned char color; // The color (background and foreground) of the CHARACTER
    
    	int current_water;   //This is a representation of how much water is contained
    	int water_need;   //this tells us how much is needed
    	//when current_water reaches with in a few points of water_need then the thirsty will 
    	//be defined as 'true'
    
    	bool thristy; //This defines the switch over from want to need
    
    	struct MEMORY
    	{
    		int size_of_memory;
    
    		COORD water_local;
    
    	};
    
    };
    How would I define anything within the memory struct? And how would I use it in a vector?

    ie
    CHARACTER Adam;
    CHARACTER MEMORY mAdam;
    Adam.mAdam.water_local....?

    I just dont know how to do it...
    Because I would like to access the variables in the memory struct with the character struct, but also I would like to occassionally just access the Memory struct.

    Should I maybe just try something else?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    use the scope resolution operator ::

    ::variable_or_function means global scope otherwise something like this...

    namespace::outer_class::first_inner_class::second_ inner_class::member

    or in your example

    CHARACTER::MEMORY MyCharMemItem;
    MyCharMemItem.size_of_memory = 1000;
    etc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    oh ah ok...well man thanks suddenly all my problems are resolved with a simple '::' heh thanks again.
    MSVC++~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested Structures Possible?
    By thetinman in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2007, 12:22 PM
  2. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 10:53 AM
  3. Nested Structures
    By Thantos in forum C Programming
    Replies: 2
    Last Post: 12-07-2003, 03:34 PM
  4. Nested Structures
    By Inept Pig in forum C Programming
    Replies: 4
    Last Post: 06-14-2002, 09:35 PM
  5. Nested structures
    By Garfield in forum C Programming
    Replies: 8
    Last Post: 10-08-2001, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21