@GManNickG이 (가) 작성한 코드 this에 관한 질문이 있습니다.친구 템플릿 기능에서 개인 회원에 액세스 할 수 없습니다.
정말 내가 (원래의 코드가 주석하고있다)과 같이print_binary_helper
의 친구 기능을 편집 무슨 일이 있었는지 이해하면 내가 볼 거라고
:
//template <typename U>
//friend print_binary_helper<U> print_binary(U value);
friend print_binary_helper<T> print_binary(T value);
//template <typename U>
//friend std::ostream& operator<<(std::ostream& sink,
// const print_binary_helper<U> source);
friend std::ostream& operator<<(std::ostream& sink,
const print_binary_helper<T> source);
//template <typename U>
//friend std::wostream& operator<<(std::wostream& sink,
// const print_binary_helper<U> source);
friend std::wostream& operator<<(std::wostream& sink,
const print_binary_helper<T> source);
대신 U 만의 T를 사용하려면 프로그램이 컴파일되지 않습니다. 어떤 사람이 나에게 잘못한 것을 설명 할 수 있었습니까? 만약 이것이 가능하다면 어떻게 할 수 있습니까?
나는 VC++ (11)를 사용하고 있는데 이것은 내가 오류입니다 :
1>anything.cpp(68): error C2248: 'print_binary_helper<T>::print_binary_helper' : cannot access private member declared in class 'print_binary_helper<T>'
1> with
1> [
1> T=int
1> ]
1> anything.cpp(31) : see declaration of 'print_binary_helper<T>::print_binary_helper'
1> with
1> [
1> T=int
1> ]
1> anything.cpp(73) : see reference to function template instantiation 'print_binary_helper<T> print_binary<int>(T)' being compiled
1> with
1> [
1> T=int
1> ]
1>anything.cpp(68): error C2248: 'print_binary_helper<T>::print_binary_helper' : cannot access private member declared in class 'print_binary_helper<T>'
1> with
1> [
1> T=unsigned __int64
1> ]
1> anything.cpp(31) : see declaration of 'print_binary_helper<T>::print_binary_helper'
1> with
1> [
1> T=unsigned __int64
1> ]
1> anything.cpp(75) : see reference to function template instantiation 'print_binary_helper<T> print_binary<unsigned __int64>(T)' being compiled
1> with
1> [
1> T=unsigned __int64
1> ]
g에서 잘 작동합니다. 4.7.2 –