D
Diwa
Does the "value" type (value as in key-value pair )of "std::map"
require a default ctor even if it is not used ?
If I comment out Line 1 in the code attached later,
i.e remove the default ctor of "value" type of map,
I get the following error:
// --------------------------------------------
/usr/include/c++/3.2.3/bits/stl_map.h:225: no matching function for
call to `FieldType::FieldType()'
temp.cpp:7: candidates are: FieldType::FieldType(const FieldType&)
temp.cpp:10: FieldType::FieldType(char, int, bool)
// --------------------------------------------
// --------------------------------------------
#include <map>
#include <string>
// --------------------------------------------
class FieldType
{
public:
FieldType( char oType, int oLen, bool oReqd ): type(oType),
len(oLen),
reqd(oReqd)
{
}
FieldType(){} // <-------- Line 1
private:
char type;
int len;
bool reqd;
};
// --------------------------------------------
int main()
{
std::map<std::string, FieldType> newOrderFields; // fieldname &
its type
newOrderFields["aotag"] = FieldType('S', 4, true); // <---------
Line 2 uses non default ctor
return 0;
}
// --------------------------------------------
require a default ctor even if it is not used ?
If I comment out Line 1 in the code attached later,
i.e remove the default ctor of "value" type of map,
I get the following error:
// --------------------------------------------
/usr/include/c++/3.2.3/bits/stl_map.h:225: no matching function for
call to `FieldType::FieldType()'
temp.cpp:7: candidates are: FieldType::FieldType(const FieldType&)
temp.cpp:10: FieldType::FieldType(char, int, bool)
// --------------------------------------------
// --------------------------------------------
#include <map>
#include <string>
// --------------------------------------------
class FieldType
{
public:
FieldType( char oType, int oLen, bool oReqd ): type(oType),
len(oLen),
reqd(oReqd)
{
}
FieldType(){} // <-------- Line 1
private:
char type;
int len;
bool reqd;
};
// --------------------------------------------
int main()
{
std::map<std::string, FieldType> newOrderFields; // fieldname &
its type
newOrderFields["aotag"] = FieldType('S', 4, true); // <---------
Line 2 uses non default ctor
return 0;
}
// --------------------------------------------