How come when I try to compile this with G++ it fails:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
template <typename T>
inlineconst& T printSomething(T a)
{
std::cout << a << std::endl;
}
int main()
{
::printSomething("Hello");
}
1 2 3 4 5 6
max4.cpp:4:17: error: expected initializer before ‘printSomething’
inlineconst& T printSomething(T a)
^
max4.cpp: In function ‘int main()’:
max4.cpp:13:3: error: ‘::printSomething’ has not been declared
::printSomething("Hello");
But if I simply switch the function header around to
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
template <typename T>
inline T const& printSomething(T a)
{
std::cout << a << std::endl;
}
int main()
{
::printSomething("Hello");
}
It works? (Notice I just switched the header of the printSomething function; "T" switched with "const&")