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

template help? how to instantiate??

Status
Not open for further replies.

haukero

Technical User
Nov 26, 2001
5
DE

hello,

i have a simple 'point'-template class with 2 parameter standard constructor! i wanna instantiate like this :

point<unsigned int> myPoint (x = 0, y = 0);

the compiler (vc++ 6 sp5) thinks 'myPoint' is a function with 2 parameters returning point<unsigned int> instead of a point instance!! ;(

so what can i do to tell the compiler it's an instance and no function! please help!!

thanks a lot,
haukero
 
What you wrote is actually a function prototype. What you need to do depends on your constructor definition, but probably will look like this:
point<unsigned int> MyPoint(0,0);
The x=0,y=0 is what's fooling the compiler I bet (looks like default args).
 

whoops, i posted the wrong instantiation code! ;)

allright, i will post my standard constructor declaration code first, this might be helpful :

// standard constructor point.h template
// 'type' is the generic template parameter
point (type x, type y);

// and this is the right instantiation code,
// which unfortunatelly doesn't work!! ;(
point <unsigned int> myPoint (unsigned int m, unsigned int n);

as you said this looks like a function prototype and the compiler also thinks so, but i think it's the right way to instantiate, so what can i do??

thanks in advance,
haukero
 
OK, try removing the &quot;unsigned int&quot; from in front of m and n - this is a function call, not a prototype - you don't need the type name in the constructor arg list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top