I have created the following HashMap class.
class HashMap: public hash_map<string, string, HashString,
HashStringCompare>
{
public:
HashMap(): hash_map<string, string, HashString, HashStringCompare>() {}
};
If I want to clone another HashMap, what should I do?
Thanks
D
> Hi,
>
> I have created the following HashMap class.
> class HashMap: public hash_map<string, string, HashString,
> HashStringCompare>
> {
> public:
> HashMap(): hash_map<string, string, HashString, HashStringCompare>() {}
> };
>
I also found that hash_map contains copy constructor, so if I write:
HashMap hash;
hash["key"] = "key";
hash["value"] = "value";
HashMap tmp;
tmp=hash;
tmp object should contains all items from hash?
> David wrote:
>
>> David wrote:
>>
>>> Hi,
>>>
>>> I have created the following HashMap class.
>>> class HashMap: public hash_map<string, string, HashString,
>>> HashStringCompare>
>>> {
>>> public:
>>> HashMap(): hash_map<string, string, HashString, HashStringCompare>()
>>> {}
>>> };
>
> I do not quite see the point of this definition. What is the advantage
> compared to:
>
> typedef hash_map< string, string , HashString, HashStringCompare >
> HashMap;
>
>>>
>> I also found that hash_map contains copy constructor, so if I write:
>> HashMap hash;
>> hash["key"] = "key";
>> hash["value"] = "value";
>>
>> HashMap tmp;
>> tmp=hash;
>>
>> tmp object should contains all items from hash?
>
> No, since you defined your own class by inheriting, you would have to
> provide your own copy constructor for HashMap. If you use the typedef from
> above, things would work like you seem to expect.
Oops, on second thought: the compiler will provide the default copy
constructor and assignment operator, which in your case should work as
expected. Yet, I still dont see why you want to inherit.
Best
Kai-Uwe Bux
> David wrote:
>
>> Hi,
>>
>> I have created the following HashMap class.
>> class HashMap: public hash_map<string, string, HashString,
>> HashStringCompare>
>> {
>> public:
>> HashMap(): hash_map<string, string, HashString, HashStringCompare>()
>> {}
>> };
I do not quite see the point of this definition. What is the advantage
compared to:
typedef hash_map< string, string , HashString, HashStringCompare > HashMap;
>>
> I also found that hash_map contains copy constructor, so if I write:
> HashMap hash;
> hash["key"] = "key";
> hash["value"] = "value";
>
> HashMap tmp;
> tmp=hash;
>
> tmp object should contains all items from hash?
No, since you defined your own class by inheriting, you would have to
provide your own copy constructor for HashMap. If you use the typedef from
above, things would work like you seem to expect.
Best
Kai-Uwe Bux
That's not copy construction. It's default construction followed by
assignment.
>
>tmp object should contains all items from hash?
>
--
Richard Herring