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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casting a Template????

Status
Not open for further replies.

Nephila

Programmer
May 14, 2002
13
ZA
I have written a Vector<T> template class, and have declared one as a double and another as an int:

Vector<double> v1(10,1.0);
Vector<int> v4;

Now I need to perform the cast operation:

v4 = (Vector<int>) v1;

Do I need to overload some operator or someting?
Any help will be greatly appreciated!
 
howabout a loop, or a function and a call to for_each (except that would require v4 to be global or static)...

v4.clear();
for(iterator i = v1.begin(); i != end(); i++)
v4.push_back((int)(*i));

You can't overload an operator, because the vector already has the operators overloaded... I'm not sure you cast a teplated class to another version of iteslf the way you are attempting....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top