I
icedac
<code>
struct nullptr_t
{
nullptr_t() : ptr_(0) {}
// pointer
template < typename T >
operator T*() const
{ return (T*)0; }
// function pointer
template < typename R >
struct typedef_fun_ptr
{
typedef R (*type)();
};
template < typename R >
operator typename typedef_fun_ptr<R>::type () const
{
return (typedef_fun_ptr<R>::type)0;
}
// arg1 ... arg10
// for member function pointer (doesn't works)
template < typename C, typename R >
struct typedef_memfun_ptr
{
typedef R (C::*type)();
};
template < typename C, typename R >
operator typename typedef_memfun_ptr<C,R>::type () const
{
return (typedef_memfun_ptr<C,R>::type)0;
}
// arg1 ... arg10
private:
void* ptr_;
};
const nullptr_t nullptr;
</code>
this is my code for nullptr in C++98.
it works for normal pointers, function pointers but not for member
pointers.
anybody knows why it doesn't works?
sample code is follows
<code>
int* p = nullptr;
std::string* s = nullptr;
void* vp = nullptr;
assert( p == nullptr );
assert( s == nullptr );
assert( sizeof(nullptr) == sizeof(void*) );
// int i = nullptr; // compile-time error: ok
// function pointer
int (*fptr1)() = nullptr;
void* (*fptr2)() = nullptr;
int (nullptr_test::*memfunp2)() =
nullptr.get_nullptr<nullptr_test,int>();
int (nullptr_test::*memfunp3)() = nullptr; // don't works
</code>
the error message is
<error_msg>
1>d:\_work\qoom-sr\qoomserver\trunk\worldserver\asioserver
\win_main.cpp(162) : error C2440: 'initializing' : couln't convert
from 'const nullptr_t' to 'int (__thiscall nullptr_test::* )(void)'
</error_msg>
struct nullptr_t
{
nullptr_t() : ptr_(0) {}
// pointer
template < typename T >
operator T*() const
{ return (T*)0; }
// function pointer
template < typename R >
struct typedef_fun_ptr
{
typedef R (*type)();
};
template < typename R >
operator typename typedef_fun_ptr<R>::type () const
{
return (typedef_fun_ptr<R>::type)0;
}
// arg1 ... arg10
// for member function pointer (doesn't works)
template < typename C, typename R >
struct typedef_memfun_ptr
{
typedef R (C::*type)();
};
template < typename C, typename R >
operator typename typedef_memfun_ptr<C,R>::type () const
{
return (typedef_memfun_ptr<C,R>::type)0;
}
// arg1 ... arg10
private:
void* ptr_;
};
const nullptr_t nullptr;
</code>
this is my code for nullptr in C++98.
it works for normal pointers, function pointers but not for member
pointers.
anybody knows why it doesn't works?
sample code is follows
<code>
int* p = nullptr;
std::string* s = nullptr;
void* vp = nullptr;
assert( p == nullptr );
assert( s == nullptr );
assert( sizeof(nullptr) == sizeof(void*) );
// int i = nullptr; // compile-time error: ok
// function pointer
int (*fptr1)() = nullptr;
void* (*fptr2)() = nullptr;
int (nullptr_test::*memfunp2)() =
nullptr.get_nullptr<nullptr_test,int>();
int (nullptr_test::*memfunp3)() = nullptr; // don't works
</code>
the error message is
<error_msg>
1>d:\_work\qoom-sr\qoomserver\trunk\worldserver\asioserver
\win_main.cpp(162) : error C2440: 'initializing' : couln't convert
from 'const nullptr_t' to 'int (__thiscall nullptr_test::* )(void)'
</error_msg>