-4

Given a class, Decimal, what is the difference between the expressions (Decimal)x and Decimal(x)?

Additionally information, in case it matters : x is an object of type MLBigNumVar, another user-defined class.

Pradhan
  • 16,391
  • 3
  • 44
  • 59
Shobha
  • 9
  • 1
  • possible duplicate of [When should static\_cast, dynamic\_cast, const\_cast and reinterpret\_cast be used?](http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used) – Emil Laine Mar 26 '15 at 03:09
  • @zenith How the heck did you know that? – Neil Kirk Mar 26 '15 at 03:11
  • @NeilKirk IMO the question is (almost) pretty clear: "What's the difference between function-style and C-style casts?" But of course I might just have misunderstood. – Emil Laine Mar 26 '15 at 03:15
  • @zenith I think it is vaguely clear at best. – Neil Kirk Mar 26 '15 at 03:16
  • Depends on context, e.g. `(Decimal)x;` is very different to `Decimal(x);` – M.M Mar 26 '15 at 07:47

1 Answers1

0

Assuming Decimal is a type name, and x is a value, then both are equivalent. They convert the value of x to the type Decimal. The first uses cast notation and the second uses functional notation, both of which have the same meaning.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • MLBigNumVar 1e18 (one product ) is actually -- 1,000,000,000,000,000,000 ( 19 digits, more than 16 digits but with trailing or exceeding digits are zeros) – Assigned successfully to decimal. MLBigNumVar 1e35 (another product) is actually -- 100,000,000,000,000,016,384,608,344,632,472,552 ( 36 digits , more than 16 digits but trailing or exceeding digits are not zeros -- assignment to decimal results in overflow ). This conversion with 36 digits would also had succeeded if all the trailing digits were zeros  Is there a work around using which the conversion can be made successful? – Shobha Mar 26 '15 at 03:50
  • @ShobhaPv: Without knowing what the types are (they're not standard C++ types, but something defined by your program or some library it uses) there's no way to say. But if it can't represent that value, then it can't represent that value. – Mike Seymour Mar 26 '15 at 12:18