nested classes
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: nested classes

  1. #1
    Join Date
    Mar 2009
    Posts
    48

    nested classes

    I have a program I need to change. There is a class which is used as the member of a list. The list is a member of another class. I need to access the list from outside of both classes.

    Code:
    /*
    class c_message_bit
    {
    	public:
    		string s_message_bit;
    		string s_type;  
    		int i_bit_number; // simple count
    		string s_separator; // Any one from vector of separator
    };
    
    class c_message_element
    {
          public:         	
             	list <c_message_bit> l_A_message_bit;
    };
    I tried something along the lines of

    Code:
        list <c_message_bit> ::iterator ilocatorlist1;
    
       for ( ilocatorlist1 = D1_message_element.l_D_message_bit.begin(); \
       ilocatorlist1 != D1_message_element.l_D_message_bit.end(); \
       	++ ilocatorlist1 )
       	{
       	       ilocatorlist1->............			
                    }
    but without success. It compiled but never entered the for loop.

    I need to compare several of the lists stored within various instances of the main class.

    Is there a way I can loop through the values of the list external to the classes?
    And if not is there a simple way to copy the list to one declared on the outside?

    The program is bit large and this requirement temporary so redesign is not an attractive route.

    Thanks for any help. Nigel
    Last edited by nigelhoath; August 7th, 2009 at 03:46 PM.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,011

    Re: nested classes

    Quote Originally Posted by nigelhoath View Post
    It compiled but never entered the for loop.
    Could it be that the list was empty?
    I need to compare several of the lists stored within various instances of the main class.

    Is there a way I can loop through the values of the list external to the classes?
    If the list is public, yes. Else it's probably easiest to add two member functions that return an iterator to the begin and end of the list, respectively.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Mar 2009
    Posts
    48

    Re: nested classes

    D_Drmmr many thanks once again.

    I thought one must be able to just use an iterator to the list of a class and indeed now I can.

    But I'm a bit wary since you recently pointed out that I couldn't change map keys, something I thought seemed logical.

    But this C++ stuff is great and really productive. I like it a lot.

    Enjoy

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center