I'm new at programming and can someone explain to me how this code work?
#include <iostream>
using namespace std;
int main () {
int a = 3, b = 4;
decltype(a) c = a;
decltype((b)) d = a;
++c;
++d;
cout << c << " " << d << endl;
}
I'm quite confused how this code run as they give me a result of 4 4
, shouldn't be like 5 5
? Because it was incremented two times by c and d? I'm getting the hang of decltype
but this assignment caught me confused how code works again.
decltype(a)
=int
. So it's the same asint c = a
; I think you can take it from there. – Gunpointd
is a reference asdecltype(paren-expr)
deduces to a reference type. – Replydecltype
corner cases. This is a highly technical question that would trip up even veterans, and it's not helpful in understanding the basics of the language. – Wellfounddecltype()
so early. It's template engineering wizardry. Not for beginners. – Phyllotaxis