This is my code:
#include <iostream>
using namespace std;
template< typename T >
T silnia( T w ) {
cout << "not special" << endl;
}
template<>
int silnia<int>( int x ) {
cout << "special" << endl;
}
int main() {
cout << silnia<double>(5) << endl;
cout << silnia<int>(5) << endl;
return 0;
}
And this is the output:
not special
nan
special
4712544
Can someone help me understand where there two additional lines came from ?
You are likely getting a compiler warning (at least) telling you that your template returns a
T
andint
respectively, yet you provide no return values, which is undefined behavior. You should return the type that the function claims it is going to.Why does it matter? Because you are using
std::cout
to try to output the returned values of these function calls.