У меня есть вопрос относительно this код, написанный @GManNickG.Друг функции шаблона недоступны для частных лиц
Я собирался увидеть если я действительно понял, что происходит, поэтому я отредактировал print_binary_helper
«s другу функции, как это (оригинальный код был прокомментирован):
//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);
использовать T вместо U но программа не будет компилироваться. Может ли кто-нибудь объяснить мне, что я сделал не так, и если это возможно, и если да, то как это можно сделать?
Я использую 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 –