English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
1

right now the following struct can hold one piece of data (data). I want it to hold 3. (int, string, string). How can i do this?

struct Node {
Node(int d) : data(d), next(0) { }
Node *next;
int data;
};

2006-10-30 13:34:19 · 2 answers · asked by ifoam 3 in Computers & Internet Programming & Design

2 answers

You need to add desired data members to your structure.
Do not forget also to change your init constructor and to add default constructor and copy constructor.

struct Node {
Node( int d, const string & _s1, const string & _s2 ) : data(d), s1(_s1), s2(_s2), next(0) { }
Node() { next=0;data=0;}
Node( const Node & n );
Node *next;
int data;
string s1;
string s2;
};

2006-10-30 14:35:15 · answer #1 · answered by alakit013 5 · 1 0

Are you referring to the data members, if so here is the solution, remember to include the pre-processor directive.

struct Node {
Node(int d) : data(d), next(0) { }
Node *next;
int data;
string data1;
string data2;
};

2006-10-30 21:41:48 · answer #2 · answered by D 4 · 0 0

fedest.com, questions and answers