是否可以写一个引用'this'指针的静态断言?我没有可用的C++ 11,而BOOST_STATIC_ASSERT不起作用。在静态断言中引用这个指针?
struct blah
{
void func() {BOOST_STATIC_ASSERT(sizeof(*this));}
};
产地:
error C2355: 'this' : can only be referenced inside non-static member functions
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE'
在MSVC 2008
动机:
#define CLASS_USES_SMALL_POOL() \
void __small_pool_check() {BOOST_STATIC_ASSERT(sizeof(*this) < SMALL_MALLOC_SIZE;} \
void* operator new(size_t) {return SmallMalloc();} \
void operator delete(void* p) {SmallFree(p);}
我想的sizeof总是编译时间?这对于这个例子很有用,但我试图实现这个宏而不会冗余地命名这个类型,参见动机部分。 –
没关系。现在是凌晨1:30。不应该在这样的时间回答问题。你是对的。 '*这个'具有明确的类型。 – StoryTeller
'int未使用[SMALL_MALLOC_SIZE-sizeof(* this)];' –