c++ - What are the names of type(myVar) and (type)myVar? Are they both bad practice? -


Almost one

but I want to know:

What are these types What is the name and they are 'bad'?

Type (myVar) is a constructor like the creator, but for the original type it is similar to the C-style which is considered bad in C ++?

(type) myVar This is definitely a C-style artist and should it behave like this?

I have seen some examples, where people replace int (a) with (int) a , it cites That the C-style version is bad / wrong, the link has been linked so far, the question says that they are both the same!

What is the name of these types

  • < Code> (type) (XPR)
    • Type (XPR) is known as function-style cast.
    • is known as a C-style artist.

    And are they 'bad'?

    First off, both mentally perfectly equivalent. They are "bad" because they are not safe - they can be equivalent to a static_cast , but evenly a reinterpret_cast , and both types and type expr it is impossible to say 1 In some cases they also ignore the access specifier (C-Style is a private heritage grade Casting is allowed inside) Also, they are not verbose in the form of a clear C ++ style, which is a After the worst thing that commonly placed to be generally means standing in C ++ and . Consider


    1 int (x) : x depending on the type, it is either Is a static_cast (for example auto x = 4.2f; ) or a reinterpret_cast (for example auto x = nullptr; on an architecture where int is enough an indicator).


  • Comments

    Popular posts from this blog

    ios - How do I use CFArrayRef in Swift? -

    eclipse plugin - Run java code error: Workspace is closed -

    c - Error on building source code in VC 6 -