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!

Template questions

Status
Not open for further replies.

Sidro

MIS
Sep 28, 2002
197
US
Im new with template and need help.I have a Class name "Data".My question is, how do I call the DoSomething
function?

void DoSomething (Data<int,int> &Direction); //prototype

void main()
{

//This is what I am using and Im not sure its right because
//I got a warning.

Data<int,int> people; //what does this mean?
DoSomething(people);


}

//DoSomething definition
void DoSomething (Data<int,int> &Direction)
{

Direction.print();


}
 
It would help if you told us what warning you got. Think of a template as a type. It makes your code a lot clearer.

typedef Data<int,int> MyType

void DoSomething (MyType &Direction); //prototype

void main()
{
MyType people; //what does this mean?
DoSomething(people);
}

//DoSomething definition
void DoSomething (MyType &Direction)
{
Direction.print();
}

In this case, it is a class definition that has two items which can be variable (in this case int) and that follow certain rules (eg assignment). You could equally use the same template with a mix of doubles, strings, integers etc

Data<int,double> id;

It really depends on what the Data template does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top