c++ - Comparing static field pointers at compile time -
I have a class B from class A which declares a static field, and B can declare a similar area Is the same name The following does not work:
struct A {static int f; }; Structure B: A {static fit F; }; // A :: FB :: is different from F structure C: A {}; // A :: FC :: F. BOOST_STATIC_ASSERT ((& amp; A :: F! = & Amp; B :: F) is similar); BOOST_STATIC_ASSERT ((& amp; A :: F == & amp; C :: F)); Although theoretically those claims can be checked when compiling time, still the expressions can not take addresses.
Is there any way to check this type of work at compile time?
Try to define the definition of fixed variables within the scope of static convulsions. / P>
It works fine with GCC 4.7.2:
struct A {static int f; }; Structure B: A {static fit F; }; Straight C: A {}; Int a: F; Int B :: f; Static_assert (& amp; A: F! = & Amp; B :: F, 'B'); Static_assert (& amp; A :: F == & amp; C :: F, "C"); Compile with int main () {} :
$ g ++ -std = gnu ++ 11 test.cpp $ ./a .out
Comments
Post a Comment