forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
#include <iostream> | ||
#include <typeinfo> | ||
|
||
int main() | ||
{ | ||
const int i = 42; | ||
auto j = i; | ||
const auto& k = i; | ||
auto* p = &i; | ||
const auto j2 = i, & k2 = i; | ||
int main() { | ||
const int i = 42; | ||
auto j = i; | ||
const auto &k = i; | ||
auto *p = &i; | ||
const auto j2 = i, &k2 = i; | ||
|
||
// print i means int, and PKi means pointer to const int. | ||
std::cout << "j is " << typeid(j).name() << "\nk is " << typeid(k).name() | ||
<< "\np is " << typeid(p).name() << "\nj2 is " | ||
<< typeid(j2).name() << "\nk2 is " << typeid(k2).name() | ||
<< std::endl; | ||
std::cout << "i is " << typeid(i).name() << "\n"; | ||
std::cout << "j is " << typeid(j).name() << "\n"; | ||
std::cout << "k is " << typeid(k).name() << "\n"; | ||
std::cout << "p is " << typeid(p).name() << "\n"; | ||
std::cout << "j2 is " << typeid(j2).name() << "\n"; | ||
std::cout << "k2 is " << typeid(k2).name() << "\n"; | ||
|
||
return 0; | ||
std::cout << std::endl; | ||
std::cout << std::boolalpha; | ||
|
||
std::cout << "i and j have same type? " | ||
<< std::is_same<decltype(i), decltype(j)>::value << "\n"; | ||
std::cout << "i and k have same type? " | ||
<< std::is_same<decltype(i), decltype(k)>::value << "\n"; | ||
std::cout << "i and j2 have same type? " | ||
<< std::is_same<decltype(i), decltype(j2)>::value << "\n"; | ||
std::cout << "j and j2 have same type? " | ||
<< std::is_same<decltype(j), decltype(j2)>::value << "\n"; | ||
std::cout << "k and k2 have same type? " | ||
<< std::is_same<decltype(k), decltype(k2)>::value << "\n"; | ||
|
||
return 0; | ||
} |