Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 3.86 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Template specialization works with g   but not with Visual C  
  2. unsigned int GetCharacterSize() const;
  3.        
  4. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int *(__thiscall ag::ui::TextArea::* const )(void) const'
  5. 2>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  6. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
  7. 2>          C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcexternLuaWrapperLuaWrapperUtil.hpp(147) : see declaration of 'luaU_get'
  8. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int *ag::ui::TextArea::* const '
  9. 2>          There is no context in which this conversion is possible
  10. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
  11. 2>          C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcexternLuaWrapperLuaWrapperUtil.hpp(131) : see declaration of 'luaU_get'
  12. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int ag::ui::TextArea::* const '
  13. 2>          There is no context in which this conversion is possible
  14. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
  15. 2>          C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcexternLuaWrapperLuaWrapperUtil.hpp(123) : see declaration of 'luaU_get'
  16. 2>C:UsersAlexDocumentsVisual Studio 2010ProjectsgamedevsrcgameluaLuaTextArea.cpp(103): error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'lua_CFunction'
  17. 2>          None of the functions with this name in scope match the target type
  18.        
  19. #include <iostream>
  20.  
  21. struct TextArea
  22. {
  23.     unsigned GetCharacterSize() const { return 0; }
  24. };
  25.  
  26. template<typename T, typename U, U (T::*)() const>
  27. int foo()
  28. {
  29.     return 1;
  30. }
  31.  
  32. template<typename T, typename U, U* (T::*)() const>
  33. int foo()
  34. {
  35.     return 2;
  36. }
  37.  
  38. int main()
  39. {
  40.     std::cout << foo<TextArea, unsigned, &TextArea::GetCharacterSize>() << 'n';
  41. }
  42.        
  43. #include <iostream>
  44.  
  45. struct WithPointer
  46. {
  47.     unsigned* GetCharacterSize() const { return nullptr; }
  48. };
  49.  
  50. struct WithoutPointer
  51. {
  52.     unsigned GetCharacterSize() const { return 0u; }
  53. };
  54.  
  55. template<bool UsePointerImplB>
  56. struct kludge
  57. {
  58.     template<typename T, typename U, U (T::*Getter)() const>
  59.     static int foo() { return 1; }
  60. };
  61.  
  62. template<>
  63. struct kludge<true>
  64. {
  65.     template<typename T, typename U, U* (T::*Getter)() const>
  66.     static int foo() { return 2; }
  67. };
  68.  
  69. int main()
  70. {
  71.     std::cout
  72.         << kludge<false>::foo<WithoutPointer, unsigned, &WithoutPointer::GetCharacterSize>() << 'n'
  73.         << kludge<true>::foo<WithPointer, unsigned, &WithPointer::GetCharacterSize>() << 'n';
  74. }
  75.        
  76. #include <iostream>
  77.  
  78. struct FooBar
  79. {
  80.   int Foo( void ) const
  81.   {
  82.    std::cout << "FooBar::Foo()" << std::endl;
  83.    return ( 0 );
  84.   }
  85.   int * Bar( void ) const
  86.   {
  87.    std::cout << "FooBar::Bar()" << std::endl;
  88.    return ( 0 );
  89.   }
  90. };
  91.  
  92. template< typename P00, typename P01, P01(P00::*p02)( void ) const >
  93. void Call()
  94. {
  95.  P00 lT;
  96.  ( lT.*p02 )();
  97. }
  98.  
  99. int main( void )
  100. {
  101.  Call< FooBar, int, &FooBar::Foo > ();
  102.  Call< FooBar, int*, &FooBar::Bar > ();
  103.  
  104.  return( 0 );
  105. }
  106.        
  107. FooBar::Foo()
  108. FooBar::Bar()