W
WL Yeow
What is the proper way to define a user defined object that is
'compatible' with STL?
I'm trying to use the inplace_merge() function. For example, I have a
wrapper class _String that contains only char* as a member. It has:
2 constructors:
_String(char*) and _String(const _String&), that uses strdup.
member fuction:
bool operator<(const _String&) const, that uses strcmp.
In my test program I have:
vector<_String> v;
v.push_back(a = _String("hello"));
v.push_back(b = _String("world"));
v.push_back(c = _String("apple"));
v.push_back(d = _String("ink"));
inplace_merge(v.begin(), v.begin()+2, v.end());
After this line, char* of _String a, b are wiped out!
Why?
It took me a while to know that I need to have a copy constructor but
that doesn't help in inplace_merge. What else is lacking?
Thanks in Advance.
'compatible' with STL?
I'm trying to use the inplace_merge() function. For example, I have a
wrapper class _String that contains only char* as a member. It has:
2 constructors:
_String(char*) and _String(const _String&), that uses strdup.
member fuction:
bool operator<(const _String&) const, that uses strcmp.
In my test program I have:
vector<_String> v;
v.push_back(a = _String("hello"));
v.push_back(b = _String("world"));
v.push_back(c = _String("apple"));
v.push_back(d = _String("ink"));
inplace_merge(v.begin(), v.begin()+2, v.end());
After this line, char* of _String a, b are wiped out!
Why?
It took me a while to know that I need to have a copy constructor but
that doesn't help in inplace_merge. What else is lacking?
Thanks in Advance.