Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-05-16 06:14:01


I have some strange behavior on RH Enterprise Linux 2.6.9-34 with gcc (GCC) 3.2.3 version and
boost::shared_ptr template.

The thning which drives me crazy compiles for one library without any problems and for the other
library it can't compile one of my typedefs.

Maybe some of you have had the similar problem before. Here some snippet:

I have some really simple type traits definitions:

    template <class T>
            struct traits_internal
    {
            typedef T type;
            typedef T& ref;
            typedef T* ptr;
            typedef const T* const_ptr;
            typedef const T& const_ref;
            typedef const T const_type;
    };

    template <class T>
            struct traits : traits_internal<T>
    {};

    template <class T>
            struct traits<T*> : traits_internal<T>
    {};

    template <class T>
            struct traits<T&> : traits_internal<T>
    {};

then I have a factory class, which can creates an empty class instance, copies the instance from
another instance or copies it from the underlying POD (raw data).

template<class Type_, class Raw_, class MemMan_>
    struct Creator
{
        public:
            typedef typename msg_factory::traits<Type_>::type val_type;
            typedef typename msg_factory::traits<Type_ >::const_type const_type;
            typedef typename msg_factory::traits<Raw_>::type raw_type;
            typedef typename msg_factory::traits<MemMan_>::type man_type;
            typedef boost::shared_ptr<val_type> smart_ptr;
            typedef boost::shared_ptr<const_type> const_smart_ptr;

    private:
            /**
             * a union container which decides which member to use, POD or Class
             * used to save space required by 2 pointers
             */
            typedef msg_factory::PointerContainer<val_type, raw_type> ptr_container;
            typedef Creator<Type_, Raw_, MemMan_> my_type;

        public:
             inline explicit Creator(man_type* m = NULL)
            : memMan(m), copy_from(static_cast<val_type*>(NULL)){}

            inline explicit Creator(const raw_type* s, man_type* m = NULL)
                    : memMan(m), copy_from(s) {}

            inline explicit Creator(const val_type& t, man_type* m = NULL)
                    : memMan(m), copy_from(&t) {}

            inline ~Creator(){}

            inline operator smart_ptr()const
      {
           return smart_ptr((copy_from.is_valid()?(copy_from.first()?(new
val_type(*copy_from.first(), memMan)):(new val_type(copy_from.second(), memMan))):(new
val_type(memMan))));
      }

        private:
        inline Creator(const my_type&)
        {}

        inline my_type& operator=(const my_type&)
        {return *this;}

        template <class OtherType_, class OtherRaw_, class OtherMemMan_>
            inline Creator(const Creator<OtherType_, OtherRaw_, OtherMemMan_>&)
        {}

        template <class OtherType_, class OtherRaw_, class OtherMemMan_>
            inline Creator& operator =(const Creator<OtherType_, OtherRaw_, OtherMemMan_>&)
        {return *this;}

                                man_type* memMan;
                                ptr_container copy_from;
};

class ClassB : public ClassA
{
 public:
        typedef Creator<ClassB, POD_B, ClassA> heap_instance;
        typedef heap_instance::smart_ptr smart_ptr;
        -->typedef heap_instance::const_smart_ptr const_smart_ptr;

 private:
        friend class Creator<ClassB, POD_B, ClassA>;

  explicit ClassB(ClassA *pcDataManager = NULL);

  explicit ClassB(const POD_B *ptCopyFromPOD, ClassA *pcDataManager = NULL);

  explicit ClassB(const ClassB &copyFromOtherClassB, ClassA *pcDataManager = NULL);

  //some class data follows
}

In this line compiler raises the error:
 ISO C++ forbids declaration of `const_smart_ptr' with no type
/some/path/here/fname:lineno: cannot declare member `
   Creator<ClassB, POD_B, ClassA>::const_smart_ptr'
   within `ClassB'
/some/path/here/fname:lineno: syntax error before `;'
   token
*** Error code 1

Somehow it does not know the type, even if I try in Creator to change the typedef from:

typedef boost::shared_ptr<const_type> const_smart_ptr;
to
typedef boost::shared_ptr<val_type> const_smart_ptr;

I still get an error at this line. And the most weired thing is, why it can compile a line
before?! Where
typedef boost::shared_ptr<val_type> smart_ptr;
is used as forward declaration?

I also tried in the Creator to change
typedef boost::shared_ptr<const_type> const_smart_ptr;
to
typedef smart_ptr const_smart_ptr;

And compiler was able to compile it... Do you have any suggestions? I am using boost 1.33_0

Many thanks,

Ovanes Markarian


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