Unrecognizable template declaration/definition

What am I not seeing here? Upon compilation I get an error on line 8:
error C2988: unrecognizable template declaration/definition


I've underlined and highlighted what I think is the offending code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <sstream>
#include <string>

namespace convert {

	template<typename TypeFrom, typename TypeTo>
	TypeTo to<TypeTo>(TypeFrom from) {
		std::stringstream stream;
		
		TypeTo ret = TypeTo();

		stream << from;
		stream >> ret;
		return ret;
	}

}

int main() {

	std::string string = "123";
	int integer = 0;


	integer = ::convert::to<int>(string);

	std::cout << integer << std::endl;

	return 0;
}


If I remove the underlined, offending code, I get different errors on line 26:

error C2672: 'convert::to': no matching overloaded function found
error C2783: 'TypeTo convert::to(TypeFrom)': could not deduce template argument for 'TypeTo'


Is this really so outlandish? Any help is appreciated.
Last edited on
Line 7: change to template<typename TypeTo, typename TypeFrom>, see http://en.cppreference.com/w/cpp/language/function_template#Template_argument_deduction
Line 8: change to TypeTo to(TypeFrom from) {
Perfect! Many thanks.
Topic archived. No new replies allowed.