Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using structures with templates

Status
Not open for further replies.

magezi

Programmer
Mar 2, 2000
118
UG
How do you pass data in a structure to a function defined in a template class.(Just like the case for primitive types int char or even arrays.)

I mean:
if you have:

template<class T>
class node{
T data;
int size;
public:
node()
{
size = 0;
}
void insert(T data);
}

it is possible to make the following declaration in the main program :

int main()
{
node<int> s;
node<float> q;
.
.
.
}

so that T can accept int or char values;

Now suppose I had data from this struycture:

struct student{
int ID;
char name[25];
}
How would I use some template fuction to pass such data to it and possibly be able to create a list ?

thanx every body.
Nkabirwa Sowed Magezi
nkabirwa@yahoo.com

A Ugandan Developer for

(1) School Management Information System(SMIS) - Foxpro 2.6 ; Ms-Acess 97

(2)Debt onitoring System(DMS) - Ms-Acess 97

(3) The Loans Recovery System(LS) - Ms- Access 97

(4) The Dry Cleaners System(DS) - Ms- Access 97
 
If you're just trying to create a linked list, why not just use the STL's list class?
 
The not-as-easy solution, if you don't want to use the STL's list class, is to define an operator =() function for the student class so that the assignment operation in the insert() function will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top