template<class T>
int myvar(T a)
{
return sizeof(T);
}
template with sizeof operator
1) is the sizeof operator resolved at run time or compile time ?
2) if it is resolved at compile time ? how does the compiler resolve this ?
i have been programming C++ for quite a long time, but i am still not sure on this ? . is it valid ?
Its my duty, to please that booty ! - John Shaft
Because, at compile time, it makes copies of the template for each type of template parameter combination.
To demonstrate:
Behold the power of cheese.. I mean.. er.. templates
To demonstrate:
// the template definitiontemplate<class T>int myvar(T a){ return sizeof(T);}// one use:long l = 0x12345678L;int a = myvar(l);//resolves to:int myvar(long a){ return sizeof(long);}// another use:double d = 1234.5678;int b = myvar(d);//resolves to:int myvar(double a){ return sizeof(double);}
Behold the power of cheese.. I mean.. er.. templates
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement