example1.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main() {
    int x = 5;
    double y = 3.14;

    // Use decltype to get the type of x
    decltype(x) a; // a is of type int
    a = 10;

    // Use decltype to get the type of y
    decltype(y) b = y * 2; // b is of type double

    std::cout << "a: " << a << std::endl;
    std::cout << "b: " << b << std::endl;

    return 0;
}
Back to decltype