Это сводит меня с ума ... У меня есть заголовок ах со следующим содержимымошибка: не подходит для «оператора <<»
#if !defined(PRETTY_PRINT_H)
#define PRETTY_PRINT_H
#include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& os, const std::vector<int> v);
#endif
источник b.cc с
...
#include "b.h"
#include "a.h"
...
void
ns::ClD::myfunc(args...) {
const std::vector<int> test(2,1);
...
std::cout << "test : " << test << std::endl;
...
}
...
и заголовок ЬН
...
namespace ns {
class ClD: public ClB
private:
virtual void
myfunc(args...);
...
При составлении b.cc, я получаю
b.cc: In member function ‘virtual void myfunc()’:
b.cc:134:26: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘const std::vector<int>’)
std::cout << "test : " << test << std::endl;
^
b.cc:134:26: note: candidates are:
...
UPDATE
Были кандидаты, поступающие из моего заголовка (номер строки не совпадают, так как я удалил несколько комментировали и пустые строки в этом OP).
В тех случаях, когда вопрос с аргументом 1, например,
In file included from /usr/include/c++/4.8/iostream:39:0,
from a.h:12,
from b.cc:13:
/usr/include/c++/4.8/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
^
/usr/include/c++/4.8/ostream:108:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.8/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
operator<<(__ios_type& (*__pf)(__ios_type&))
^
/usr/include/c++/4.8/ostream:117:7: note: no known conversion for argument 1 from ‘const std::vector<int>’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
...
В тех случаях, когда вопрос с аргументом 2,
In file included from /usr/include/c++/4.8/iostream:39:0,
from a.h:12,
from b.cc:13:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
^
/usr/include/c++/4.8/ostream:548:5: note: template argument deduction/substitution failed:
b.cc:135:29: note: cannot convert ‘test’ (type ‘const std::vector<int>’) to type ‘const unsigned char*’
std::cout << "test : " << test << std::endl;
^
In file included from /usr/include/c++/4.8/iostream:39:0,
from a.h:12,
from b.cc:13:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
^
/usr/include/c++/4.8/ostream:543:5: note: template argument deduction/substitution failed:
b.cc:135:29: note: cannot convert ‘test’ (type ‘const std::vector<int>’) to type ‘const signed char*’
std::cout << "test : " << test << std::endl;
^
...
Но я не уверен, что если какой-либо из кандидаты, проанализированные в сообщенных сообщениях, действительно поступают из моего прототипа или из других включенных стандартных заголовков.
Любые подсказки о том, в чем проблема?
Является ли ваш оператор признанным в пространстве имен, который не является глобальным? – krzaq
При уменьшении до [голого минимума] (http://ideone.com/n3Xg1n) он работает. Так что независимо от проблемы, ваши фрагменты кода не демонстрируют это. – StoryTeller
Ошибка, вероятно, в одном из ваших «...» Когда вы не знаете, в чем проблема, если предположить, что проблема не проблема, это часто проблема. Код компилируется: https://godbolt.org/g/AKHBPK – xaxxon