Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Intrusive] Compilation error with Visual Studio 2008
From: info-tibo (info-tibo_at_[hidden])
Date: 2010-03-13 14:06:53


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net