template<class T&>

Hi,

is it valid to put the ampersand with the class/typename keyword instead of with the function?
No. The template parameter is an identifier.
... so it would have to be a declarator to work? ... would that make sense in any way or just be redundant.
Yes. You don't write int as int& everywhere in your code. You might only want a reference sometimes, othertimes by pointer or value. You're just telling the compiler of a new type, just like int or char.

You don't need the ampersand in the template itself:

1
2
3
4
5
template<typename T> // There's a type called T used here
void Print(T& t, T other_t) // Take t by ref, take other_t by value
{
	std::cout << t << " " << other_t << "\n";
}
Good example. Thanks guys.
Topic archived. No new replies allowed.