I've got the code:
string key = "", value = "", type = "";
while(in)
{
getline(in, key, '=');
getline(in, value, '\n');
getline(in, type, '\n');
in.get(); // get the dividing empty line
CommonParamValue *paramValue = CreateParamValue(type);
paramValue->SetValue(value);
params.insert(make_pair(key, *paramValue)); // PROBLEM
delete paramValue;
}
When I call params.insert(make_pair(key, *paramValue));
I get an element of map with correct key end EMPTY value. When I check
paramsIter = params.find(paramKey);
if (paramsIter != params.end())
{
if( ("" == paramsIter->second.GetValue())
...
}
All the time condition "" == paramsIter->second.GetValue()
is true, but it must not be so!
Additional information:
class CommonParamValue
{
public:
virtual void SetValue(string value){}
virtual string GetValue(){ return ""; }
};
class StringParamValue : public CommonParamValue
{
string str;
public:
StringParamValue(){}
virtual void SetValue(string value){str = value;}
virtual string GetValue() {return str;}
};
CommonParamValue* Report::CreateParamValue(const string &strType) const
{
if (strType == "int")
{
return (new IntParamValue());
}
else if(strType == "string")
{
return (new StringParamValue());
}
else
{
// error
exit(1);
}
}
The question is why when I do params.insert(make_pair(key, *paramValue));
I always get an element with correct key and an EMPTY value? What is wrong?