问题
Here is a simplified example:
class A
{
enum {OFFSET = 4}; //Due to packing
bool m_bool;
};
template<class T>
class B : public A
{
MyClass<T> m_class;
};
Now supposing that class A can make use of a subset of MyClass's functionality via a base-class of MyClass, what I wish to do is verify an assumption about the location of 'm_class' with respect to an instance of class A.
I have tried the following code from within a member-function of class B, but it gives an error ("expected constant expression"):
static_assert ((byte *)nullptr + OFFSET ==
(byte *)&((B<T> *)nullptr)->m_class, "Error 'm_class' incorrectly located!");
Is this simply too ambitious for the current version of the compiler?
来源:https://stackoverflow.com/questions/11313534/in-vs2010-is-it-possible-to-use-static-assert-to-verify-an-assumption-about-the