::const_iterator ii;
since mytest is const.
>
> for(ii=mytest.tests.begin();ii!=mytest.tests.end();++ii)
> {
> myclass* my=new myclass;
> memcpy(my,ii->second,sizeof(ii->second));
> tests.insert(make_pair(ii->first,my));
> }
>
> }
>
> there was an error: "c:\Ug\Solution1\test\test.cpp(16): error C2679:
> binary '=' : no operator found which takes a right-hand operand of
> type 'std::_Tree<_Traits>::const_iterator' " at the for loop point.
> can anybody tell me why and what's the right way to do the copy
> constructor? thanks
Read the article on the law of the Big Two that I gave in my previous
post.
Here's a tip: If you see memcpy in C++ code, that's bad (usually).
Prefer to give myclass proper copy semantics so you can say:
*my = *( ii->second );
Better still would be to use a smart pointer that does -- depending on
your needs -- either reference counting (e.g., std::tr1::shared_ptr,
boost::shared_ptr, Loki::SmartPtr, or the one in FAQ 16.22 and
following) or deep copying (e.g., Loki::SmartPtr) for you
automatically.
Cheers! --M