daily pastebin goal
86%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <utility>
  2.  
  3. class A {
  4. public:
  5.     A() { }
  6. };
  7.  
  8. class B {
  9. public:
  10.     B() { }
  11. };
  12.  
  13. typedef std::pair<A*, B*> ABPair;
  14.  
  15. int main(int argc, char* argv[])
  16. {
  17.     B* b = 0;               // no C2440
  18.     ABPair p2(new A(), b);
  19.  
  20.     ABPair p1(new A(), 0);  // C2440
  21.  
  22.     return 0;
  23. }
  24.    
  25. 1>ClCompile:
  26. 1>  test.cpp
  27. 1>c:program files (x86)microsoft visual studio 10.0vcincludeutility(163): error C2440: 'initializing' : cannot convert from 'int' to 'B *'
  28. 1>          Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
  29. 1>          c:program files (x86)microsoft visual studio 10.0vcincludeutility(247) : see reference to function template instantiation 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base<_Ty,int>(_Other1 &&,_Other2 &&)' being compiled
  30. 1>          with
  31. 1>          [
  32. 1>              _Ty1=A *,
  33. 1>              _Ty2=B *,
  34. 1>              _Ty=A *,
  35. 1>              _Other1=A *,
  36. 1>              _Other2=int
  37. 1>          ]
  38. 1>          c:userscharliearnolddocumentsvisual studio 2010projectstesttesttest.cpp(20) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<A*,int>(_Other1 &&,_Other2 &&)' being compiled
  39. 1>          with
  40. 1>          [
  41. 1>              _Ty1=A *,
  42. 1>              _Ty2=B *,
  43. 1>              _Other1=A *,
  44. 1>              _Other2=int
  45. 1>          ]
  46. 1>c:program files (x86)microsoft visual studio 10.0vcincludeutility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::second' : member could not be initialized
  47. 1>          with
  48. 1>          [
  49. 1>              _Ty1=A *,
  50. 1>              _Ty2=B *
  51. 1>          ]
  52. 1>          c:program files (x86)microsoft visual studio 10.0vcincludeutility(167) : see declaration of 'std::_Pair_base<_Ty1,_Ty2>::second'
  53. 1>          with
  54. 1>          [
  55. 1>              _Ty1=A *,
  56. 1>              _Ty2=B *
  57. 1>          ]
  58. 1>
  59. 1>Build FAILED.
  60.    
  61. #include <utility>
  62.  
  63. class A {
  64. public:
  65.     A() { }
  66. };
  67.  
  68. class B {
  69. public:
  70.     B() { }
  71. };
  72.  
  73. typedef std::pair<A*, B*> ABPair;
  74.  
  75. ABPair make_ABPair(A* pa, B* pb)
  76. {
  77.     return ABPair(pa, pb);
  78. }
  79.  
  80.  
  81. int main(int argc, char* argv[])
  82. {
  83.     B* b = 0;               // no C2440
  84.     ABPair p2(new A(), b);
  85.  
  86.     //ABPair p1(new A(), 0);  // C2440
  87.     ABPair p1(make_ABPair(new A(), 0));
  88.  
  89.     return 0;
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top