Chicken or the Egg problem...

This is a discussion on Chicken or the Egg problem... within the C++ Programming forums, part of the General Programming Boards category; Having trouble with some code, does anyone know how to do this: class Location contains a vector of pointers to ...

  1. #1
    Evil Member
    Join Date
    Jan 2002
    Posts
    638

    Chicken or the Egg problem...

    Having trouble with some code, does anyone know how to do this:

    class Location contains a vector of pointers to Boxes. struct Box contains a Location for that Box.

    Whichever is declared first does not have the definition of the other. Any ideas?

  2. #2
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Does this help?
    Code:
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    typedef struct BOX_STRUCT
    {
    	int	Length, Width, Height, Volume;
    	vector<BOX_STRUCT>::iterator	BoxLocation; // vector iterator to self
    } Box;
    
    class Location
    {
    public:	
    	Location() {}
    	~Location() {}
    
    	vector<Box>		ListOfBoxes;
    };
    
    int main()
    {
    	Location	MyBoxes;
    	Box		CurrentBox;
    
    	MyBoxes.ListOfBoxes.push_back(CurrentBox);
    	
    	// Do your thing...
    
    	return 0;
    }
    I'm not real heavy on STL, so this may not be "correct," but it compiles.
    Last edited by fletch; 08-18-2002 at 09:11 PM.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Chicken or the Egg problem...
    The egg came first. But that's OT
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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