Reputation: 11
I have a template function . This function returns the same template type . Ex: It takes T type variable and return the T type variable. Now can I cast the return type T variable using static cast to Uint32.Will I get any errors
Upvotes: 1
Views: 180
Reputation: 2189
From what I understand you have a function that looks like
template <class T>
T noop (T a) {
return a;
}
and you want to cast the result of it
uint32 i = static_cast<uint32>(noop(val));
This will succeed if val
is of a type that can be cast to uint32 and fail if it isn't.
uint32 i = static_cast<uint32>(noop(uint32(0))); // ok
uint32 i = static_cast<uint32>(noop("asdf")); // not-ok
Upvotes: 7