[Boost.Intrusive] Compilation error with Visual Studio 2008
Hello, For a project, I created a class allowing to reference some objects, and I use Boost.Intrusive. I started coding this class using Code::Blocks and gcc 3.4.5 . But now I want to use Visual Studio 9, and I simply added the class to the project. And then... it doesn't compile... The code is here : ----------------------------------------------------------------------------------------------------------------------------------------- #ifndef _BASE_EQUALREFSYSTEM_H_ #define _BASE_EQUALREFSYSTEM_H_ #include <boost/intrusive/list.hpp> namespace base { //! Convenient typedef typedef boost::intrusive::list_member_hook< boost::intrusive::link_mode<boost::intrusive::normal_link> > EqualRefSysHook; //! A class to handle self referencing systems /** Each object can point to a target, in order to interact with it. How to use: \code // First, you have to derivate this class class MyClass : public EqualRefSystem { // code... } // Then you can, in your main function, create these objects: MyClass* myClassPointer = new MyClass; // for example: repeated 200 times // Afterthat, you can point each object to another. When you have finished // you can simply call: delete myClassPointer; \endcode **/ class EqualRefSystem { public: //! The hook used by the intrusive list ReferencedBy EqualRefSysHook ERSMemberHook; public: //! Constructor EqualRefSystem() :Target(0),RefCount(0) {} //! Destructor /** Safe destructor : all references and target are reseted. **/ virtual ~EqualRefSystem() { resetTarget(); unlink(); } //! Returns the targeted object /** \return A pointer to the object targeted by this EqualRefSystem. **/ inline EqualRefSystem* getTarget() const { return Target; } //! Sets the target /** \param tgt : The new target. 0 means 'no target'. If tgt == this, the target is set to 0. This function is stable and very fast, you can use it without any restriction. **/ inline void setTarget(EqualRefSystem* tgt) { if(tgt == Target) return; if(tgt == this) tgt = 0; if(Target) Target->dereference(this); Target = tgt; if(Target) Target->reference(this); } //! Resets the target /** This function is a synonym for setTarget(0). **/ inline void resetTarget() { if(Target) Target->dereference(this); Target = 0; } //! Returns whether a target is set or not /** This function is a synonym for (getTarget() != 0). \return True if a target is set, else false. **/ inline bool hasTarget() const { return Target != 0; } //! Unlink from all objects which targets this one /** This function resets the target of all objects targeting this EqualRefSystem. **/ inline void unlink() { while(!ReferencedBy.empty()) ReferencedBy.begin()->resetTarget(); RefCount = 0; } //! Returns the number of objects targeting this one /** \return The number of objects targeting this EqualRefSystem. Constant-time. **/ inline unsigned int getNumberOfReferences() const { return RefCount; } private: //! Reference an object in this EqualRefSystem inline void reference(EqualRefSystem* toRef) { if(!toRef || toRef == this) return; ReferencedBy.push_back(*toRef); RefCount++; } //! Dereference an object from this EqualRefSystem inline void dereference(const EqualRefSystem* toDeref) { if(!toDeref || toDeref == this) return; ReferencedBy.erase(ReferencedBy.iterator_to(*toDeref)); RefCount--; } //! Targeted object EqualRefSystem* Target; //! Objects that reference this EqualRefSystem boost::intrusive::list< EqualRefSystem, boost::intrusive::member_hook<EqualRefSystem,EqualRefSysHook,&EqualRefSystem::ERSMemberHook>, boost::intrusive::constant_time_size<false> > ReferencedBy; //! Number of references unsigned int RefCount; }; } #endif // _BASE_EQUALREFSYSTEM_H_ ----------------------------------------------------------------------------------------------------------------------------------------- VCC told me 42 errors, all related to the first one: line 112 : C2327: 'base::EqualRefSystem::ERSMemberHook' : is not a type name, static, or enumerator I searched the doc about the C2327, but it doesn't helped me. Thanks in advance, Darktib PS: I apologize for my english, I'm french.
AMDG info-tibo wrote:
For a project, I created a class allowing to reference some objects, and I use Boost.Intrusive. I started coding this class using Code::Blocks and gcc 3.4.5 . But now I want to use Visual Studio 9, and I simply added the class to the project. And then... it doesn't compile...
The code is here : ----------------------------------------------------------------------------------------------------------------------------------------- <snip> -----------------------------------------------------------------------------------------------------------------------------------------
VCC told me 42 errors, all related to the first one: line 112 : C2327: 'base::EqualRefSystem::ERSMemberHook' : is not a type name, static, or enumerator
I think that MSVC is wrong here by 3.3.6. You can work around this by using a base hook instead of a member hook. In Christ, Steven Watanabe
Hello, For this class I can't use base hooks - except if there are no solutions (for code design)... I have another file with similar classes and a base hook, and it works, apparently because the list is defined in another class than in the class of the hook i.e, the following works flawlessly: class A { public: BaseHookType hook; } class B { public: List<BaseHookType,&A::hook> lst; } Are there really no solutions to use member_hook Thanks, Darktib ----- Original Message ----- From: "Steven Watanabe" <watanabesj@gmail.com> To: <boost-users@lists.boost.org> Sent: Saturday, March 13, 2010 9:25 PM Subject: Re: [Boost-users] [Boost.Intrusive] Compilation error with Visual Studio 2008
AMDG
info-tibo wrote:
For a project, I created a class allowing to reference some objects, and I use Boost.Intrusive. I started coding this class using Code::Blocks and gcc 3.4.5 . But now I want to use Visual Studio 9, and I simply added the class to the project. And then... it doesn't compile...
The code is here : ----------------------------------------------------------------------------------------------------------------------------------------- <snip> -----------------------------------------------------------------------------------------------------------------------------------------
VCC told me 42 errors, all related to the first one: line 112 : C2327: 'base::EqualRefSystem::ERSMemberHook' : is not a type name, static, or enumerator
I think that MSVC is wrong here by 3.3.6. You can work around this by using a base hook instead of a member hook.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG info-tibo wrote:
For this class I can't use base hooks - except if there are no solutions (for code design)...
I have another file with similar classes and a base hook, and it works, apparently because the list is defined in another class than in the class of the hook i.e, the following works flawlessly: class A { public: BaseHookType hook; } class B { public: List<BaseHookType,&A::hook> lst; }
Are there really no solutions to use member_hook
Apparently it works if you add an extra level of indirection: template<class> struct make_member_hook { typedef boost::intrusive::member_hook<EqualRefSystem,EqualRefSysHook,&EqualRefSystem::ERSMemberHook> type; }; //! Objects that reference this EqualRefSystem boost::intrusive::list< EqualRefSystem, typename make_member_hook<EqualRefSystem>::type, boost::intrusive::constant_time_size<false> > ReferencedBy; In Christ, Steven Watanabe
It work perfectly, thanks a lot! Darktib
Apparently it works if you add an extra level of indirection:
template<class> struct make_member_hook { typedef boost::intrusive::member_hook<EqualRefSystem,EqualRefSysHook,&EqualRefSystem::ERSMemberHook> type; };
//! Objects that reference this EqualRefSystem boost::intrusive::list< EqualRefSystem, typename make_member_hook<EqualRefSystem>::type, boost::intrusive::constant_time_size<false> > ReferencedBy;
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
info-tibo
-
Steven Watanabe