Weird problem with boost::noncopyable and boost::mutex

Hi,
*I was doing a program in C++ where I simulate a Java's ArrayList...*
*
*
template <class T>
class Duo
{
public:
Duo *next;
T element;
Duo(T el,Duo *sig)
{
element=el;
next=sig;
}
~Duo() {};
Duo* getNext() {return next;}
T getElement() {return element;}
void setNext(Duo *myNext) {next=myNext;}
void setElement(T el){element=el;}
};
template <class T>
class ArrayList
{
public:
Duo <T>*Ptr_First;
Duo <T>*Ptr_Last;
ArrayList(){Ptr_First = Ptr_Last = NULL;};
~ArrayList(){}
void insert(T el);
std::pair

The thing is that I instanciated an ArrayList object and called the "insert" method and I received an error from boost::mutex AND boost::noncopyable!! and I am not using them at all!! This is the code that generates the error: ArrayList<ObjectA> myArrayListA; ObjectA myObjectA; myArrayListA.insert(myObjectA);
Maybe ObjectA has a member of type boost::mutex? insert() invokes compiler-generated copy-constructor of ObjectA, which in turn tries to copy the mutex. In short, you ObjectA is non-copyable.

You were right.
Actually ObjectA has a member that is ListObject that has a member
boost::mutex.
I really need to use this objects this way and the LisObject object needs
that mutex, is any other way I can use them and not recesive this problem?
Thanks!!
Dann
On Wed, Mar 17, 2010 at 7:00 PM, Igor R
The thing is that I instanciated an ArrayList object and called the "insert" method and I received an error from boost::mutex AND boost::noncopyable!! and I am not using them at all!! This is the code that generates the error: ArrayList<ObjectA> myArrayListA; ObjectA myObjectA; myArrayListA.insert(myObjectA);
Maybe ObjectA has a member of type boost::mutex? insert() invokes compiler-generated copy-constructor of ObjectA, which in turn tries to copy the mutex. In short, you ObjectA is non-copyable. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Thu, Mar 18, 2010 at 2:37 PM, Daniel V
You were right. Actually ObjectA has a member that is ListObject that has a member boost::mutex. I really need to use this objects this way and the LisObject object needs that mutex, is any other way I can use them and not recesive this problem? Thanks!!
Dann
You could use a pointer to your object, which is non-copyable and store the pointer in the list than. If you decide to go that way consider using boost pointer containers, which wrap pointer semantics and do automatic memory management of contained pointers. Here is the lib ref: http://www.boost.org/doc/libs/1_42_0/libs/ptr_container/doc/ptr_container.ht... Regards, Ovanes

You were right. Actually ObjectA has a member that is ListObject that has a member boost::mutex. I really need to use this objects this way and the LisObject object needs that mutex, is any other way I can use them and not recesive this problem? Thanks!!
You can either store [smart] pointer to the object, like Ovanes proposed, or make your ObjectA copyable by storing [smart]ptrs to non-copyable members. In the latter case you have to think how ObjectA internals should be copied in the copy-constructor and operator=().
participants (3)
-
Daniel V
-
Igor R
-
Ovanes Markarian