-
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
-
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.
-
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!
-
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.
-
I want to copy the contents of one container into another. Please show an example. thanks!
-
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] << ' ';