type conversion in c++

i just stumbled over the following code snippet
1
2
3
4
5
6
7
8
9
char c = 'a';

int i = (int) c; // 1
int j = int(c); // 2

cout << i << endl;
cout << j << endl;

// both, i and j, have the same value of 97 


the result of i and j on the console is absolutely the same. i am a bit confused why the second conversion works and why there is no documentation about the "functional" conversion on the msdn.

in c# (VS 2010) for example, it is possible to drill into method definitions by just set your cursor over a method name and pressing F12. this approach helped me a lot while do programming with c#. in there in vs 2010 for c++ something comparable to like in vs 2010 for c#?
Both are valid cast syntax. The ASCII value of 'a' is 97. I'm not sure what you're asking.
Number 2 is a constructor. You are constructing an int passing c as the argument and assigning that to j. It works because, somewhere in the language there is a int constructor that accepts a char as argument defined.
i tried to googling for the documentation about the int constructor, but there aren't any information about that. where can i find more information about that?

in the .net world for example, there is MSDN the central and official point to get more information about a class or method. is there also an official documentation for c++?
http://cplusplus.com/doc/tutorial/operators/

edit

Just thought it would be good to add, you should (or better, you should) use c++ casting.

http://cplusplus.com/doc/tutorial/typecasting/
Last edited on
I would also add that when you want some documentation about c++ that would surely work on any compiler consider advising also a different documentation besides msdn.

This will ensure that there your case is not about some Microsoft specific implementation.
I'll dive

The expression int(c) is covered in the standard under §5.2.3[expr.type.conv]/1, which says

A simple-type-specifier (7.1.6.2) or typename-specifier (14.6) followed by a parenthesized expression-list constructs a value of the specified type given the expression list. If the expression list is a single expression, the type conversion expression is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression (5.4).


This sends us to chapter §5.4[expr.cast], which describes the expression (int)c, aka the C-style cast.
Topic archived. No new replies allowed.