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 5981617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:58:08+00:00 2026-05-22T21:58:08+00:00

What are the rules to determine whether or not a particular static_cast will call

  • 0

What are the rules to determine whether or not a particular static_cast will call a class’s constructor? How about c style/functional style casts?

  • 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-22T21:58:09+00:00Added an answer on May 22, 2026 at 9:58 pm

    Any time a new object is created, a constructor is called. A static_cast always results in a new, temporary object (but see comment by James McNellis) either
    immediately, or through a call to a user defined conversion. (But in
    order to have an object of the desired type to return, the user defined
    conversion operator will have to call a constructor.)

    When the target is a class type, C style casts and functional style
    casts with a single argument are, by definition, the same as a
    static_cast. If the functional style cast has zero or more than one
    argument, then it will call the constructor immediately; user defined
    conversion operators are not considered in this case. (And one could
    question the choice of calling this a “type conversion”.)

    For the record, a case where a user defined conversion operator might be
    called:

    class A
    {
        int m_value;
    public
        A( int initialValue ) : m_value( initialValue ) {}
    };
    
    class B
    {
        int m_value;
    public:
        B( int initialValue ) : m_value( initialValue ) {}
        operator A() const { return A( m_value ); }
    };
    
    void f( A const& arg );
    
    B someB;
    f( static_cast<A>( arg ) );
    

    In this particular case, the cast is unnecessary, and the conversion
    will be made implicitly in its absence. But in all cases: implicit
    conversion, static_cast, C style cast ((A) someB) or functional
    style cast (A( someB )),
    B::operator A() will be called.)

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

Sidebar

Related Questions

What are the C++ rules for calling the base class constructor from a derived
Using jQuery, what is the easiest way to determine whether a particular element is
As I understand there is no clear rule to determine whether Java method will
Are there any utilities that will crawl a site and determine which css rules
Are there rules of thumb that help determine which to use in what case?
Rules like A parent object will have up to 2 children could be enforced
The CSS rules visibility:hidden and display:none both result in the element not being visible.
Not sure whether this pertains to VS 2010 or to the upgraded framework, but...
The Finder uses some kind of rules to determine if an Item can be
If one is checking a user's roles to determine whether they may access a

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.