#include <iostream>
#include <typeinfo>
constint func1();
constint& func2();
struct X { double d; };
auto main() -> int {
int i{0};
const X* x = new X();
decltype(func1()) f1;
decltype(func2()) f2 = f1;
decltype(i) i1;
decltype(x->d) d1;
decltype((x->d)) d2 = d1;
std::cout << "Declare type func1() " << f1<< "\n";
std::cout << "Declare type func2() " << f2<< "\n";
std::cout << "Declare type i " << i1 << std::endl;
std::cout << "Declare type d1 " << d1 << std::endl;
std::cout << "Declare type d2 " << d2 << std::endl;
return 0;
}
constint func1() {
return 1;
}
constint & func2() {
int temp{2};
int * n = newint;
*n = temp;
return *n;
}
I understand f1 & f2, but I don't understand the following 2 declarations:
1 2
decltype(x->d) d1;
decltype((x->d)) d2 = d1;
which occur on page 12 of the book. Firstly , what is "d", and secondly
why do I have to initialise " decltype((x->d)) d2" to d1 in order for the code to compile ?