D
dragoncoder
Hi all,
I am reading Modern C++ design by Andrei Alexandrescu. In the
Techniques chapter I came across this code for using a run time
assertion. Here is the code.
#include <cassert>
template <class To, class From>
To safe_reinterpret_cast ( From from)
{
std::assert ( sizeof (From) <= sizeof (To) );
return reinterpret_cast <To> (from);
}
int main()
{
char c = 'a';
char* pc = safe_reinterpret_cast <char*> (c);
}
I don't see any problem with the code, but when I compile this I get
the following error.
=> g++ p4.cxx
p4.cxx: In function `To safe_reinterpret_cast(From)':
p4.cxx:6: syntax error before `static_cast'
Can someone please explain why the error is coming and where is the
static_cast involved here ?
Thanks in advance.
I am reading Modern C++ design by Andrei Alexandrescu. In the
Techniques chapter I came across this code for using a run time
assertion. Here is the code.
#include <cassert>
template <class To, class From>
To safe_reinterpret_cast ( From from)
{
std::assert ( sizeof (From) <= sizeof (To) );
return reinterpret_cast <To> (from);
}
int main()
{
char c = 'a';
char* pc = safe_reinterpret_cast <char*> (c);
}
I don't see any problem with the code, but when I compile this I get
the following error.
=> g++ p4.cxx
p4.cxx: In function `To safe_reinterpret_cast(From)':
p4.cxx:6: syntax error before `static_cast'
Can someone please explain why the error is coming and where is the
static_cast involved here ?
Thanks in advance.