BOOST_STATIC_ASSERT is not compiled

Look at example code: class CBase { public: virtual ~CBase(){} virtual void foo()const = 0; }; template <class T> class CTest { private: BOOST_STATIC_ASSERT((boost::is_base_of<CBase,T>::value_type)); public: CTest(){} void what()const { } }; class CDerived : public CBase { CTest<CDerived> m_a; public: CDerived(){} virtual void foo()const{m_a.what();} }; int main(int argc, _TCHAR* argv[]) { CDerived d; d.foo(); return 0; } I am using the BOOST_STATIC_ASSERT to make sure the template parameter of the CTest class is inherited from some specific class (in particular CBase in this example). But this code is not compiled. I am using Visual C++ 7 compiler. What is my error?

Look at example code:
BOOST_STATIC_ASSERT((boost::is_base_of<CBase,T>::value_type));
Should be: BOOST_STATIC_ASSERT((boost::is_base_of<CBase,T>::value)); The code does then compile with gcc, but not with VC++ 7.1. I think the problem here is that at the point you instantiate CTest, CDerived is an incomplete type - the static assert then fails because the compiler can't tell whether CDerived has any bases or not. I'm not sure if this helps, but if the test were to be instantiated from one of CDerived's member functions, then CDerived would be complete at the point of instantiation and the problem would go away. As it stands though you've given the compiler a cyclic instantiation-dependency, which it's free to resolve any way it chooses. HTH, John.
participants (2)
-
John Maddock
-
OSA