Skip to content

Commit

Permalink
try to fixed pezy#39
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Dec 17, 2015
1 parent cf7e3a4 commit 7e8d18f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions ch02/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ Exercise 2.35
> const auto j2 = i, &k2 = i;
> ```
- `i` is `const int`.
- `j` is `int`.
- `k` is `const int&`.
- `p` is `const int *`.
Expand Down
40 changes: 27 additions & 13 deletions ch02/ex2_35.cpp
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;
}

0 comments on commit 7e8d18f

Please sign in to comment.