Is it possible to declare a variable var_b
of the same type as another variable, var_a
?
For example:
template <class T> void foo(T t) { auto var_a = bar(t); //make var_b of the same type as var_a } F_1 bar(T_1 t) { } F_2 bar(T_2 t) { }
A defining variable is a symbol, such as x, used to describe any number. When a variable is used in an function, we know that it is not just one constant number, but that it can represent many numbers. Variables are instrumental in understanding problems relating to graphing.
Declaring (Creating) Variablestype variableName = value; Where type is one of C++ types (such as int ), and variableName is the name of the variable (such as x or myName). The equal sign is used to assign values to the variable.
When declaring variables, you usually use a Dim statement. A declaration statement can be placed within a procedure to create a procedure-level variable.
Sure, use decltype
:
auto var_a = bar(t); decltype(var_a) b;
You can add cv-qualifiers and references to decltype
specifiers as if it were any other type:
const decltype(var_a)* b;
decltype(var_a) var_b;
And a Lorem Ipsum to reach the required minimum of 30 characters per answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With