Answer the question
In order to leave comments, you need to log in
What happens to a function when I specify the argument type as auto?
Are you creating multiple functions with different parameters?
How effective or inefficient is it?
Example
#include <iostream>
void print(auto x) {
std::cout << x << std::endl;
}
int main() {
print(5);
print("hello");
print('c');
}
Answer the question
In order to leave comments, you need to log in
This function declaration is equivalent to a function template:
template<typename T>
void print(T x) {
std::cout << x << std::endl;
}
print<int>, print<const char*>, print<char>
. void print(const auto& x) {
std::cout << x << std::endl;
}
void print(auto& x) {
std::cout << x << std::endl;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question