Boost logo

Boost Users :

From: Allen Cronce (acronce_at_[hidden])
Date: 2005-09-29 08:08:20


No one responded to this so I'm sending it again.

I understand that the work around is to not use stack objects. But the documentation indicates that this should work. So perhaps I'm seeing a bug with the Pointer Container Library and the CodeWarrior MSL?

Best regards,
--
Allen Cronce

-------- Original Message --------
Subject: Error populating pointer container with stack based objects
Date: Fri, 23 Sep 2005 15:04:31 -0700
From: Allen Cronce <acronce@earthlink.net>
Reply-To: acronce@earthlink.net
To: boost-users@lists.boost.org


Hi all,

I'm seeing a compile error when trying to populate a pointer container with stack based objects. What's supposed to happen is the stack-based object should be cloned and the resulting new object inserted in the container. But I'm only able to insert new objects, not stack-based ones. The object I'm trying to copy is Cloneable in accordance with the Pointer Container Library docs (I think). I'm using the Boost CVS build from September 15th under CodeWarrior 9.5/MSL on Mac OS X.

Here's a code sample that demonstrates the problem:

--snip--

// Forward reference for required clone function
class    StringWrapper;
StringWrapper* new_clone( const StringWrapper& a );

class    StringWrapper : public boost::totally_ordered<StringWrapper>
    {
    public:
        StringWrapper()
            {
            }

        StringWrapper(LPCTSTR in_psz):
            m_str(in_psz)
            {
            }                     
         
        ~StringWrapper()
            {
            }
       
        StringWrapper(const StringWrapper& in_RHS ):
            m_str(in_RHS.m_str)
            {
            }
                       
        StringWrapper&        operator=( const StringWrapper& in_RHS    )
            {
            m_str    = in_RHS.m_str;
            return *this;
            }
                               
        StringWrapper*        clone() const
            {
            return do_clone();
            }

        bool operator < (const StringWrapper& in_RHS) const
            {
            return (m_str < in_RHS.m_str);
            }
           
        bool operator == (const StringWrapper& in_RHS) const
            {
            return (m_str == in_RHS.m_str);
            }

        std::string    m_str;
   
    private:
        virtual StringWrapper* do_clone() const
            {
            return new StringWrapper(*this);
            }
    };

// Function needed for pointer container library object cloning
StringWrapper* new_clone( const StringWrapper& a )
    {
    return a.clone();
    }

// test code
typedef    boost::ptr_vector<StringWrapper>    StringWrapperVector;
typedef    StringWrapperVector::iterator       StringWrapperVectorIterator;
StringWrapperVector        swv1;

// The following generates a compile error:
StringWrapper    tempString("Copy me!");
swv1.push_back(tempString);        // should call the StringWrapper clone method

// The following works correctly:
swv1.push_back(new StringWrapper("I'm dynamic 1!"));
swv1.push_back(new StringWrapper("I'm dynamic 2!"));

--snip--

The compiler error is as follows:

Error   : function call '[boost::ptr_vector<StringWrapper, boost::heap_clone_allocator, std::allocator<void *>>].push_back({lval} StringWrapper)' does not match
'boost::ptr_sequence_adapter<StringWrapper, std::vector<void *, std::allocator<void *>>, boost::heap_clone_allocator>::push_back(StringWrapper *)' (non-static)
MiniTest.c line 33622     swv1.push_back(tempString);  // should call the StringWrapper clone method

Any suggestions would be appreciated.

Best regards,
--
Allen Cronce


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