Re: map (associative array) loses values?
Jim Langston wrote in message...
I can understand not wanting to copy the map being 3.3 megabytes. Be
aware, however, that if you copy your class, the map will get copied
also.
So just make sure you pass your class by reference than by value. One
way
to ensure this is to disable copying of your class. The normal way to
do
this is to create a copy constructor ( and assignment operator) and make
them private to the class. That way if you accidently write some code
that would create a copy of the class, it won't compile and you will
realize it.
For the SearchText class that would be:
class SearchText
{
public:
// ...
private:
// Disable copy and assignment by making private.
SearchText( SearchText const&) {}
SearchText& operator=( SearchText const&) {}
}
Just empty copy constructor and assignment operator's private to the
class.
Just a note. I noticed in that code that in operator= I don't have a
return
statement. I looked in my own code where I'm doing this same thing and
also
don't have a return statement. I don't know if that's a compiler flaw not
catching it, or the standard allows it. I think, however, that
SearchText& opeator=( SearchText const& ) { return this; }
would be more correct, even though it will never be called.
AFAIK, you don't need to define it, just declare it.
( only define operator= if you're using it inside the class.).
class SearchText{
// Disable copy and assignment by making private.
SearchText( SearchText const&);
SearchText& operator=( SearchText const&);
// or
// void operator=( SearchText const&);
public:
// ....
};
--
Bob R
POVrookie