D
Damon
Hi,
Created the template function below but the g++ compiler keeps
complaining "no matching function for call to....".
Is there a way to make it work? Thank you.
==========snip part of class method===========
template <class TYPE> TYPE *field( const std::string &field_name ) {
if( !b_default ) {
throw runtime_error("{persistent}<field>: Not in default "
"mode, cannot use the field method!");
}
std::map<std::string, std::vector<std::string> >::iterator iter;
iter = m_table.find( field_name );
if( m_table.end()==iter ) {
std::cerr << "{persistent}<associate>: The field, '" <<
field_name << "' is not in the table <" << tname <<
">." << std::endl;
throw std::runtime_error("{persistent}<associate>: The field,
'" +
field_name + "' is not in the table
<" + tname +
">");
}
std::string d_type = (m_table[ field_name ])[0];
if( "string"==d_type || "date"==d_type ) {
dbUtils::data_type<std::string>* current =
(dbUtils::data_type<std::string>*) data_values[ field_name
];
return current->value;
}
else if( "double"==d_type ) {
dbUtils::data_type<double>* current =
(dbUtils::data_type<double>*) data_values[ field_name ];
return current->value;
}
else if( "int"==d_type ) {
dbUtils::data_type<int>* current =
(dbUtils::data_type<int>*) data_values[ field_name ];
return current->value;
}
else if( "long"==d_type ) {
dbUtils::data_type<long>* current =
(dbUtils::data_type<long>*) data_values[ field_name ];
return current->value;
}
else if( "bool"==d_type ) {
dbUtils::data_type<bool>* current =
(dbUtils::data_type<bool>*) data_values[ field_name ];
return current->value;
}
else {
std::cerr << "{persistent}<field>: Encounter unknown "
"data type" << std::endl;
throw std::runtime_error("{persistent}<field>: Encounter "
"unknown data type");
}
}
Created the template function below but the g++ compiler keeps
complaining "no matching function for call to....".
Is there a way to make it work? Thank you.
==========snip part of class method===========
template <class TYPE> TYPE *field( const std::string &field_name ) {
if( !b_default ) {
throw runtime_error("{persistent}<field>: Not in default "
"mode, cannot use the field method!");
}
std::map<std::string, std::vector<std::string> >::iterator iter;
iter = m_table.find( field_name );
if( m_table.end()==iter ) {
std::cerr << "{persistent}<associate>: The field, '" <<
field_name << "' is not in the table <" << tname <<
">." << std::endl;
throw std::runtime_error("{persistent}<associate>: The field,
'" +
field_name + "' is not in the table
<" + tname +
">");
}
std::string d_type = (m_table[ field_name ])[0];
if( "string"==d_type || "date"==d_type ) {
dbUtils::data_type<std::string>* current =
(dbUtils::data_type<std::string>*) data_values[ field_name
];
return current->value;
}
else if( "double"==d_type ) {
dbUtils::data_type<double>* current =
(dbUtils::data_type<double>*) data_values[ field_name ];
return current->value;
}
else if( "int"==d_type ) {
dbUtils::data_type<int>* current =
(dbUtils::data_type<int>*) data_values[ field_name ];
return current->value;
}
else if( "long"==d_type ) {
dbUtils::data_type<long>* current =
(dbUtils::data_type<long>*) data_values[ field_name ];
return current->value;
}
else if( "bool"==d_type ) {
dbUtils::data_type<bool>* current =
(dbUtils::data_type<bool>*) data_values[ field_name ];
return current->value;
}
else {
std::cerr << "{persistent}<field>: Encounter unknown "
"data type" << std::endl;
throw std::runtime_error("{persistent}<field>: Encounter "
"unknown data type");
}
}