我创建了两种特殊类型,我想在我的应用程序的 get_property_function.hpp 中使用它们:
typedef boost::function<std::string ()> GetFunction;
typedef map<std::string, GetFunction> PropertyToGetFunction;
typedef boost::function<std::string (LPARAM)> GetEventFunction;
typedef map<std::string, GetEventFunction> PropertyToGetEventFunction;
我在 PropertyManager.hpp 中定义了以下几行:
PropertyToGetFunction create_get_map();
PropertyToGetEventFunction create_event_get_map();
PropertyToGetFunction property2getFunction;
PropertyToGetEventFunction property2getEventFunction;
我在我的 PropertyManager.cpp 中实现它们:
PropertyToGetFunction PropertyManager::create_get_map()
{
PropertyToGetFunction property2getFunction;
property2getFunction[string("1.1.3.4.1.1")]=&getReceiptPrinter_DeviceCapability;
...
return property2getFunction;
}
PropertyToGetEventFunction PropertyManager::create_event_get_map()
{
PropertyToGetEventFunction property2getEventFunction;
property2getEventFunction[string("105")]=&getPTRRetractBinThreshold_UserEvent;
...
return property2getEventFunction;
}
我分配给我的地图的方法在get_property_function
.
get_property_function.hpp:
...
std::string getPTRRetractBinThreshold_UserEvent(LPARAM lParam);
...
get_property_function.cpp:
...
std::string getPTRRetractBinThreshold_UserEvent(LPARAM lParam)
{
string result = "";
//I will do some process in here and will save it in result var.
return result;
}
...
我用来getPropertyValue
在我的地图中找到正确的方法:
string PropertyManager::getPropertyValue(string property_id)
{
string result_value = "No Property Found";
if (!isReadable(property_id))
{
return "Error";
}
else
{
PropertyToGetFunction::const_iterator it =property2getFunction.find(property_id);
if ( it != property2getFunction.end() )
{
GetFunction function = it->second;
result_value = function();
}
}
return result_value;
}
string PropertyManager::getPropertyValue(string property_id, LPARAM lParam)
{
string result_value = "No Property Found";
if (!isReadable(property_id))
{
return "Error";
}
else
{
PropertyToGetEventFunction::const_iterator it = property2getEventFunction.find(property_id);
if ( it != property2getEventFunction.end() )
{
GetEventFunction function = it->second;
result_value = function(lParam);
}
}
return result_value;
}
getPropertyValue(string property_id)
工作正常,我对此没有任何问题,但getPropertyValue(string property_id, LPARAM lParam)
导致编译错误:
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1146): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1148): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1150): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(348): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(367): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(386): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(404): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(422): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::basic_istream<_Elem,_Traits>, LPWORD )'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(35) : while compiling class template member function 'void boost::property_tree::customize_stream<Ch,Traits,E>::extract(std::basic_istream<_Elem,_Traits> &,E &)'
1> with
1> [
1> Ch=char,
1> Traits=std::char_traits<char>,
1> E=LPWORD ,
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(190) : see reference to class template instantiation 'boost::property_tree::customize_stream<Ch,Traits,E>' being compiled
1> with
1> [
1> Ch=char,
1> Traits=std::char_traits<char>,
1> E=LPWORD
1> ]
1> D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(186) : while compiling class template member function 'boost::optional<T> boost::property_tree::stream_translator<Ch,Traits,Alloc,E>::get_value(const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> T=LPWORD ,
1> Ch=char,
1> Traits=std::char_traits<char>,
1> Alloc=std::allocator<char>,
1> E=LPWORD ,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/detail/ptree_implementation.hpp(661) : see reference to class template instantiation 'boost::property_tree::stream_translator<Ch,Traits,Alloc,E>' being compiled
1> with
1> [
1> Ch=char,
1> Traits=std::char_traits<char>,
1> Alloc=std::allocator<char>,
1> E=LPWORD
1> ]
1> D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/detail/ptree_implementation.hpp(732) : see reference to function template instantiation 'Type boost::property_tree::basic_ptree<Key,Data>::get_value<Type>(void) const' being compiled
1> with
1> [
1> Type=LPWORD,
1> Key=std::string,
1> Data=std::string
1> ]
1> ..\..\..\..\..\..\..\Source-Code\Device-Manager\source\property\get_property_functions.cpp(3328) : see reference to function template instantiation 'Type boost::property_tree::basic_ptree<Key,Data>::get<LPWORD>(const boost::property_tree::string_path<String,Translator> &) const' being compiled
1> with
1> [
1> Type=LPWORD,
1> Key=std::string,
1> Data=std::string,
1> String=std::string,
1> Translator=boost::property_tree::id_translator<std::string>
1> ]
我确定我的参数定义有问题boost::function
。你能告诉我我做错了什么吗?