중첩 네임 스페이스 안에있는 friend 함수로 템플릿 클래스를 만들려고합니다. 모든 네임 스페이스를 제거하거나 모든 템플릿 화를 제거하면 올바르게 작동합니다. 그러나 둘 다 있으면 컴파일되지 않습니다.중첩 네임 스페이스 안에 friend 함수가있는 템플릿 클래스
오류 C2248 :
이namespace MyNamespace { // Forward declaration template <typename Type> class Container; // Forward declaration namespace AccessPrivateImplementation { template <typename Type> Type getValue(Container<Type>* container); } // Templatized class template <typename Type> class Container { friend Type AccessPrivateImplementation::getValue(Container<Type>* volume); private: Type value; }; // Friend function inside a namespace namespace AccessPrivateImplementation { template <typename Type> Type getValue(Container<Type>* container) { return container->value; } } } int main(int argc, char* argv[]) { MyNamespace::Container<int> cont; MyNamespace::AccessPrivateImplementation::getValue(&cont); return 0; }
컴파일러 (VS2010)가 나를 알려줍니다의 일부 코드를 살펴 보자 'MyNamespace에 :: 컨테이너 :: 값'MyNamespace에 '클래스에서 선언 private 멤버에 액세스 할 수 없습니다 : : 컨테이너 '
실종 된 사람이 있습니까?
이 Container''전'getValue'를 선언하십시오. – Pubby
이 스레드가 도움이 될 수 있습니다 http://stackoverflow.com/questions/16288446/i-need-help-fixing-an-error-message-error-lnk2019-unresolved-external-symbol/16288486#16288486 –
@Pubby - 고마워, getValue는 Container에 대한 포인터를 사용하기 때문에 두 번째로 올 필요가 있습니다. –