Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:24:01+00:00 2026-05-19T01:24:01+00:00

This shows the gist of it: #include <utility> class A { public: A() {

  • 0

This shows the gist of it:

#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;
}

Is there a better way to make the p1 declaration work than just forcing a cast, e.g.
ABPair p1(new A(), (B*)NULL)? This seems like it would be pretty common & that there would be a “right” way to do it .. and that casting it is not the right way.

On VS 2010, here’s the full error:

1>ClCompile:
1>  test.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(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.0\vc\include\utility(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:\users\charliearnold\documents\visual studio 2010\projects\test\test\test.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.0\vc\include\utility(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.0\vc\include\utility(167) : see declaration of 'std::_Pair_base<_Ty1,_Ty2>::second'
1>          with
1>          [
1>              _Ty1=A *,
1>              _Ty2=B *
1>          ]
1>
1>Build FAILED.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:24:02+00:00Added an answer on May 19, 2026 at 1:24 am

    Not really. nullptr will fix this in C++0x, but for now, write (B*)0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey i have this div that shows as a popup: <div class=popup> </div> Then
A quick Google search of this issue shows it's common, I just can't for
This question and answer shows how to send a file as a byte array
This code works in a windows forms application (it shows the preview) but not
This is pretty weird. I have my Profiler open and it obviously shows that
In this tutorial I am reading , Dave Ward creates a page that shows
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
I have a window in WPF which shows some media contents. This content contains
I have this code, showmessage('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID); if removedir('C:\TEMP\'+openfiles[openfilelist.ItemIndex].ID) then showmessage('Removed') else showmessage('Failed'); The message shows
By default Windows (XP) shows the underlined hotkeys only, when ALT is pressed. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.