템플릿 typename 인수에 인수로 참조를 전달하는 방법이 있습니까? 예를 들어 int에 대한 참조를 전달하기 위해 int를 전달하는 대신 의미합니다.
template <typename T>
struct Foo
{
Foo(T arg) : ptr(arg) {}
T ptr;
};
int main()
{
int* a = new int(6);
Foo<decltype(a)> foo1(a); // ptr is a copy of a pointer
Foo<decltype(&a)> foo1(&a); // ptr seems to be a pointer to a pointer
}
클래스에서 T & T로 만들어 'ptr'멤버를 포인터에 대한 참조로 만들 수 있다는 것을 알고 있지만 템플릿 인수에 전달 된 인수 에서이 작업을 수행 할 수 있는지 궁금합니다.
decltype제목 그대로 문자 그대로 쓸 수 있기 때문에 계속 머무르고 싶다고 생각합니다.Foo<int*&>