Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- class A {
- public:
- A() { }
- };
- class B {
- public:
- B() { }
- };
- typedef std::pair<A*, B*> ABPair;
- int main(int argc, char* argv[])
- {
- B* b = 0; // no C2440
- ABPair p2(new A(), b);
- ABPair p1(new A(), 0); // C2440
- return 0;
- }
- 1>ClCompile:
- 1> test.cpp
- 1>c:program files (x86)microsoft visual studio 10.0vcincludeutility(163): error C2440: 'initializing' : cannot convert from 'int' to 'B *'
- 1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
- 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
- 1> with
- 1> [
- 1> _Ty1=A *,
- 1> _Ty2=B *,
- 1> _Ty=A *,
- 1> _Other1=A *,
- 1> _Other2=int
- 1> ]
- 1> c:userscharliearnolddocumentsvisual studio 2010projectstesttesttest.cpp(20) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<A*,int>(_Other1 &&,_Other2 &&)' being compiled
- 1> with
- 1> [
- 1> _Ty1=A *,
- 1> _Ty2=B *,
- 1> _Other1=A *,
- 1> _Other2=int
- 1> ]
- 1>c:program files (x86)microsoft visual studio 10.0vcincludeutility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::second' : member could not be initialized
- 1> with
- 1> [
- 1> _Ty1=A *,
- 1> _Ty2=B *
- 1> ]
- 1> c:program files (x86)microsoft visual studio 10.0vcincludeutility(167) : see declaration of 'std::_Pair_base<_Ty1,_Ty2>::second'
- 1> with
- 1> [
- 1> _Ty1=A *,
- 1> _Ty2=B *
- 1> ]
- 1>
- 1>Build FAILED.
- #include <utility>
- class A {
- public:
- A() { }
- };
- class B {
- public:
- B() { }
- };
- typedef std::pair<A*, B*> ABPair;
- ABPair make_ABPair(A* pa, B* pb)
- {
- return ABPair(pa, pb);
- }
- int main(int argc, char* argv[])
- {
- B* b = 0; // no C2440
- ABPair p2(new A(), b);
- //ABPair p1(new A(), 0); // C2440
- ABPair p1(make_ABPair(new A(), 0));
- return 0;
- }
Add Comment
Please, Sign In to add comment