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

  • Home
  • SEARCH
  • 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 7057197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:25+00:00 2026-05-28T03:57:25+00:00

Possible Duplicate: What is the difference between (type)value and type(value)? I am mainly a

  • 0

Possible Duplicate:
What is the difference between (type)value and type(value)?

I am mainly a C# developer and so do a lot of explicit casting using syntax like: (type)variable, with (int)100.0004d as an example. As such, when writing code in C++, I often use the same syntax. However, I have seen (and even used) code in other cases where the same cast is achieved using the syntax type(variable) with int(100.0004) as an example.

I was just curious as to what the difference between the two methods were and whether there were any implications in using one over the other.

Example:

double someDouble = 100.00456;

// Cast the double using the (type)variable syntax
int firstCastValue = (int)someDouble;

// Cast the double using the type(variable) syntax
int secondCastValue = int(someDouble);
  • 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-28T03:57:26+00:00Added an answer on May 28, 2026 at 3:57 am

    The two are exactly the same, and this is true for any type.

    Personally, I would avoid the first form, (T)x, in favour of an explicit static cast:

    y = static_cast<T>(x);
    

    This expresses that you want to convert x to the type T.

    The second form is rather more evocative of a constructor call, and that’s sometimes preferable:

    v = std::vector<int>(10);  // not: v = static_cast<std::vector<int>>(10)
    

    To repeat, both forms are entirely equivalent, and it’s a matter of taste which you prefer. I would use static cast for “converting” and constructor-syntax for “constructing”, if that makes any sense.

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

Sidebar

Related Questions

Possible Duplicates: C++ cast syntax styles What is the difference between (type)value and type(value)
Possible Duplicate: What is the difference between (type)value and type(value)? If you have a
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: Ruby: difference between || and ‘or’ Using Ruby || and or are
Possible Duplicate: Difference between using var and not using var in JavaScript For the
Possible Duplicate: Difference between void main and int main? Alright, so I'm using bloodshed
Possible Duplicate: Difference between using var and not using var in JavaScript Hello, I
Possible Duplicate: Difference between “var” and “object” in C# I would like to know
Possible Duplicate: Difference between try-catch syntax for function What is the difference in the

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.