Thread: data passing

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    77

    data passing

    Here's what I want to do:
    I have data contained in "Asn_t" which is in header file "task.h".
    I want to pass this data into the container "PathCont_t" in the Data_t struct which is located in the file "navigate.h". How can I do this? I have an example of the data structures below...I just can't figure out how to pass the data.
    Thanks in advance!

    Code:
    //File task.h
    
    class TASKS
    {
    public:
    
        struct Path_struct {
    	    int             Packet_Type;
    	    int             sending_location;
    	    char            sending_sign[10];
    	    int             rcv_location;
    	    path_struct     path_data;
    	    Path_struct() : Packet_Type(Path_Type) {}
        };
    
        // Types of assignments that can be sent over a network
        enum AsnType_t
        {
            PATH
        };
    
        // message received over a network
        struct Asn_t
        {
            // Type of assignment received
            AsnType_t type;
    
            PATH_struct        Path_Data;
        };
    
        // Container type for assignments received.
        typedef std::vector<Asn_t> AsnCont_t;
    
    
    }; // end class TASKS
    
    
    
    //File navigate.h
    
    class PATHS
    {
    public:
    
        // Max number of Paths
        enum {MAX_PATHS   = 10};
    
        /// Path type. 
        typedef std::vector<unsigned> Paths_t;
    
        /// Path type that contains the name of the Path.
        struct Path_t
        {
            std::string name;
            PathPts_t  points;
        };
    
        /// Container of Paths.
        typedef std::vector<Path_t> PathCont_t;
    
    
        struct Data_t
        {
            // All Paths for the exercise. 
            PathCont_t Paths;
    
            Data_t() : Paths(MAX_PathS) {}
        };
    
    }; // end class PATHS
    Last edited by jerrykelleyjr; 12-27-2004 at 12:12 PM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok I really hate to say this when you did post a fairly thorough question with code, but could you please clarify this a bit. I have no idea what you mean by your question. Perhaps an example of the code that you have already tried could steer me in the right direction.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    I apologize as the question was not at all very well constructed. I think simply what I'm trying to comprehend is passing data from one container to another. I listed the code (data structures) only because it's the code I'm using. Really any example of how to pass data from one container to another would suffice...at least it gives me an idea of what to start with. Thanks!

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The process will be container and implementation specific. For example, you can access an element in most containers without removing them, so do you want to empty one container into another or just copy contents of one container into another. For arrays you can access elements using pointers or the [] operator. For non-STL lists you can use pointers. For STL containers like vectors you can use iterators, the [] operator, and a variety of methods like front(), back(), begin(), end() to access elements. The other STL containers all have their element access methods as do trees, etc.

    Instances of user defined classes can be passed between containers just like plain old data types like int, char, etc.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    I want to copy the contents of one container into another. Please show an example. thanks!

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    //copy one array into another
    const int MAX = 2;
    int array1[MAX];
    int array2[MAX];
    int i;
     
    //fill array1
    for(i = 0; i < MAX; ++i)
       array1[i] = i;
     
    //copy array1 to array2
    for(i = 0; i < MAX; ++i)
       array2[i] = array1[i];
     
    //display array2
    for(i = 0; i < MAX; ++i)
       std::cout << array2[i] << ' ' ;  
     
     
    //copy one vector into another.
    std::vector<int> v1;
    std::vector<int> v2;
     
    //fill v1
    for(i = 0; i < MAX; ++i)
      v1.push_back(i);
     
    //copy v1 into v2
    std::copy(v1.begin(), v1.end(), v2.begin());
     
    //displayv2
    for(i = 0; i < MAX; ++i)
      std::cout << v2[i] << ' ';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  3. Data member passing
    By wirefree101 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2006, 01:41 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Passing structure data to a function?
    By diddy02 in forum C Programming
    Replies: 8
    Last Post: 08-17-2002, 04:15 PM