Это sesms в C++, это хорошо, чтобы повторно назначить ссылку, привязывая ее к другому объекту. Однако приведенный ниже код не подлежит подбору:Почему нельзя переназначить ссылку на istream/ostream?
ostream &os_ref = cerr;
os_ref = cout;
Может кто-нибудь сказать мне, что не так? Информация об ошибках приведена ниже.
temp.cpp: In function ‘int main()’:
temp.cpp:15:12: error: use of deleted function ‘std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&)’
os_ref = cout;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from temp.cpp:1:
/usr/include/c++/4.9/ostream:58:11: note: ‘std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&)’ is implicitly deleted because the default definition would be ill-formed:
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
^
/usr/include/c++/4.9/ostream:58:11: error: use of deleted function ‘std::basic_ios<char>& std::basic_ios<char>::operator=(const std::basic_ios<char>&)’
In file included from /usr/include/c++/4.9/ios:44:0,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from temp.cpp:1:
/usr/include/c++/4.9/bits/basic_ios.h:66:11: note: ‘std::basic_ios<char>& std::basic_ios<char>::operator=(const std::basic_ios<char>&)’ is implicitly deleted because the default definition would be ill-formed:
class basic_ios : public ios_base
^
In file included from /usr/include/c++/4.9/ios:42:0,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from temp.cpp:1:
/usr/include/c++/4.9/bits/ios_base.h:789:5: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private
operator=(const ios_base&);
^
In file included from /usr/include/c++/4.9/ios:44:0,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from temp.cpp:1:
/usr/include/c++/4.9/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
«В C++ это хорошо, чтобы повторно присвоить ссылку, ограничивающую его к другому объекту.» ** ** НЕПРАВИЛЬНО. – juanchopanza
Ответ должен быть здесь: http://stackoverflow.com/questions/8070537/how-should-i-correctly-assign-cout-to-a-static-ostream-reference-variable?rq=1 – stefan
Нет, это здесь: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list –