그것은 허용되지 않습니다.
그러나 다음은 허용됩니다.
template <std::string * temp> //pointer to object
void f();
template <std::string & temp> //reference to object
void g();
C ++ Standard (2003)의 §14.1 / 6,7,8을 참조하세요.
삽화:
template <std::string * temp> //pointer to object
void f()
{
cout << *temp << endl;
}
template <std::string & temp> //reference to object
void g()
{
cout << temp << endl;
temp += "...appended some string";
}
std::string s; //must not be local as it must have external linkage!
int main() {
s = "can assign values locally";
f<&s>();
g<s>();
cout << s << endl;
return 0;
}
산출:
can assign values locally
can assign values locally
can assign values locally...appended some string