A
Alexander Stippler
In some situations I can apply a C-style cast,
but no static_cast. I'm not quite sure about the
differences in such places. A little example:
template <typename T>
class Dummy {
public:
Dummy(int i) {}
};
template <typename T>
void dummy(const Dummy<T> &a) {}
int
main()
{
int i=6;
// a traditional cast works ...
dummy((const Dummy<int> &)i);
// but the static_cast is an invalid type conversion.
dummy(static_cast<const Dummy<int> &>(i));
return 0;
}
I know, that a static_cast to Dummy<int> would have worked in the second
call, but what's the difference between the two casts in the main() above?
regards,
alex
but no static_cast. I'm not quite sure about the
differences in such places. A little example:
template <typename T>
class Dummy {
public:
Dummy(int i) {}
};
template <typename T>
void dummy(const Dummy<T> &a) {}
int
main()
{
int i=6;
// a traditional cast works ...
dummy((const Dummy<int> &)i);
// but the static_cast is an invalid type conversion.
dummy(static_cast<const Dummy<int> &>(i));
return 0;
}
I know, that a static_cast to Dummy<int> would have worked in the second
call, but what's the difference between the two casts in the main() above?
regards,
alex