2013-10-02 2 views
0

Я создал два специальных типов, которые я хочу использовать в моем 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; 
} 

методы I присвоенные к моей карте определены в 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. Можете ли вы сказать мне, что я делаю неправильно?

+0

Что такое "property_manager.cpp (189)"? Каков код на этой строке? –

+0

property2getFunction [string ("105")] \t \t \t \t = & getPTRRetractBinThreshold_UserEvent; –

+0

И что такое подпись 'getPTRRetractBinThreshold_UserEvent'? –

ответ

2

В следующей строке:

property2getFunction[string("105")] = &getPTRRetractBinThreshold_UserEvent 

Там же попытка присвоить функцию, имеющую string(LPARAM) подписи к boost::functionstring(void), имеющей подпись (см вашего GetFunction типа). Вот почему вы получаете эту ошибку компиляции.

Вместо этого вы, вероятно, должны были использовать property2getEventFunction.