Whilst trying auto feature, am hitting this following issue:
My code:
#include <iostream>
#include <math.h>
auto new_func(auto num){
return pow(num, 0.5) ;
}
int main(int argC, char* argV[]){
float num(0) ;
std::cout<<"Square root function !\nEnter a number: " ;
std::cin>>num ;
std::cout<<"Square root of "<<num<<" = "<<my_func(num)<<std::endl ;
return 0 ;
}
Error:
./First_go.cpp:10:20: error: parameter declared ‘auto’
auto new_func(auto num){
^
./First_go.cpp:10:23: warning: ‘new_func’ function uses ‘auto’ type specifier without trailing return type [enabled by default]
auto new_func(auto num){
^
./First_go.cpp: In function ‘auto new_func()’:
./First_go.cpp:12:16: error: ‘num’ was not declared in this scope
return pow(num, 0.5) ;
How to resolve this issue, why is this complaining, why cant it make num auto ? ??