0 / 0 / 0
Регистрация: 08.12.2020
Сообщений: 11

Как вывести переменную класса boost :: any?

11.04.2022, 21:03. Показов 16084. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Впрнцп, я пытаюсь сделать что то подобное:

Кликните здесь для просмотра всего текста

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <boost/any.hpp>
 
#include "iostream"
 
#include "fstream"
 
class meth {
  public:
    boost::any console;
  std::ofstream out;
  public:
    meth() {}
  template < typename T1 >
    auto input(T1 & consolen) {
      consolen = "wellldonw";
      printer(console);
    }
 
  template < typename T >
    auto printer(T & t) {
      std::cout << t;
    }
};
 
int main() {
  meth methode;
  methode.input(methode.console);
}


Но увы, делать cout any я видимо не могу:

Кликните здесь для просмотра всего текста
PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
test.cpp: In instantiation of ‘auto meth::printer(T&) [with T = boost::any]’:
test.cpp:16:9:   required from ‘auto meth::input(T1&) [with T1 = boost::any]’
test.cpp:28:30:   required from here
test.cpp:22:15: error: no match for ‘operator<<(operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>} and ‘boost::any’)
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:108:7: note: candidate: ‘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>]’
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/10/ostream:108:36: note:   no known conversion for argument 1 from ‘boost::any’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&){aka ‘std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/ostream:117:7: note: candidate: ‘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>]’
  117 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/10/ostream:117:32: note:   no known conversion for argument 1 from ‘boost::any’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&){aka ‘std::basic_ios<char>& (*)(std::basic_ios<char>&)}
  117 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/10/ostream:127:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  127 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/10/ostream:127:30: note:   no known conversion for argument 1 from ‘boost::any’ to ‘std::ios_base& (*)(std::ios_base&)’
  127 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/10/ostream:166:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  166 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:166:23: note:   no known conversion for argument 1 from ‘boost::any’ to ‘long int’
  166 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/10/ostream:170:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  170 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:170:32: note:   no known conversion for argument 1 from ‘boost::any’ to ‘long unsigned int’
  170 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/ostream:174:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  174 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:174:23: note:   no known conversion for argument 1 from ‘boost::any’ to ‘bool’
  174 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/10/ostream:784,
                 from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/bits/ostream.tcc:91:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]’
   91 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/ostream.tcc:92:22: note:   no known conversion for argument 1 from ‘boost::any’ to ‘short int’
   92 |     operator<<(short __n)
      |                ~~~~~~^~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:181:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  181 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:181:33: note:   no known conversion for argument 1 from ‘boost::any’ to ‘short unsigned int’
  181 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/ostream:784,
                 from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/bits/ostream.tcc:105:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]’
  105 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/ostream.tcc:106:20: note:   no known conversion for argument 1 from ‘boost::any’ to ‘int’
  106 |     operator<<(int __n)
      |                ~~~~^~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:192:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  192 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:192:31: note:   no known conversion for argument 1 from ‘boost::any’ to ‘unsigned int’
  192 |       operator<<(unsigned int __n)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/10/ostream:201:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  201 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:201:28: note:   no known conversion for argument 1 from ‘boost::any’ to ‘long long int’
  201 |       operator<<(long long __n)
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/ostream:205:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  205 |       operator<<(unsigned long long __n)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:205:37: note:   no known conversion for argument 1 from ‘boost::any’ to ‘long long unsigned int’
  205 |       operator<<(unsigned long long __n)
      |                  ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/ostream:220:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  220 |       operator<<(double __f)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:220:25: note:   no known conversion for argument 1 from ‘boost::any’ to ‘double’
  220 |       operator<<(double __f)
      |                  ~~~~~~~^~~
/usr/include/c++/10/ostream:224:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type =
std::basic_ostream<char>]’
  224 |       operator<<(float __f)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:224:24: note:   no known conversion for argument 1 from ‘boost::any’ to ‘float’
  224 |       operator<<(float __f)
      |                  ~~~~~~^~~
/usr/include/c++/10/ostream:232:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  232 |       operator<<(long double __f)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:232:30: note:   no known conversion for argument 1 from ‘boost::any’ to ‘long double’
  232 |       operator<<(long double __f)
      |                  ~~~~~~~~~~~~^~~
/usr/include/c++/10/ostream:245:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  245 |       operator<<(const void* __p)
      |       ^~~~~~~~
/usr/include/c++/10/ostream:245:30: note:   no known conversion for argument 1 from ‘boost::any’ to ‘const void*’
  245 |       operator<<(const void* __p)
      |                  ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/ostream:784,
                 from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/bits/ostream.tcc:119:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’
  119 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/ostream.tcc:120:34: note:   no known conversion for argument 1 from ‘boost::any’ to ‘std::basic_ostream<char>::__streambuf_type*{aka ‘std::basic_streambuf<char>*}
  120 |     operator<<(__streambuf_type* __sbin)
      |                ~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/boost/throw_exception.hpp:23,
                 from /usr/include/boost/type_index/stl_type_index.hpp:33,
                 from /usr/include/boost/type_index.hpp:29,
                 from /usr/include/boost/any.hpp:18,
                 from test.cpp:1:
/usr/include/boost/assert/source_location.hpp:58:55: note: candidate: ‘template<class E, class T> std::basic_ostream<_CharT, _Traits>& boost::operator<<(std::basic_ostream<_CharT, _Traits>&, const boost::source_location&)’
   58 | template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ostream<E, T> & os, source_location const & loc )
      |                                                       ^~~~~~~~
/usr/include/boost/assert/source_location.hpp:58:55: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const boost::source_location&’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/boost/type_index/type_index_facade.hpp:14,
                 from /usr/include/boost/type_index/stl_type_index.hpp:22,
                 from /usr/include/boost/type_index.hpp:29,
                 from /usr/include/boost/any.hpp:18,
                 from test.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6468:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
 6468 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6468:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   ‘boost::any’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/bits/ios_base.h:46,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/system_error:262:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::error_code&)’
  262 |     operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
      |     ^~~~~~~~
/usr/include/c++/10/system_error:262:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const std::error_code&’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:506:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)’
  506 |     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:506:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘boost::any’)
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:511:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)’
  511 |     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:511:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘char’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:517:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)’
  517 |     operator<<(basic_ostream<char, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:517:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘char’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:523:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)’
  523 |     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:523:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘signed char’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:528:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)’
  528 |     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:528:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘unsigned char’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:589:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)’
  589 |     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:589:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   mismatched types ‘const _CharT*’ and ‘boost::any’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/ostream:784,
                 from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/bits/ostream.tcc:321:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)’
  321 |     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
      |     ^~~~~~~~
/usr/include/c++/10/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const char*’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:606:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)’
  606 |     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:606:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const char*’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:619:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)’
  619 |     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:619:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const signed char*’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:624:5: note: candidate: ‘template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)’
  624 |     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:624:5: note:   template argument deduction/substitution failed:
test.cpp:22:15: note:   cannot convert ‘t’ (type ‘boost::any’) to type ‘const unsigned char*’
   22 |   std :: cout << t;
      |   ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/iostream:39,
                 from test.cpp:3:
/usr/include/c++/10/ostream:773:5: note: candidate: ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&)’
  773 |     operator<<(_Ostream&& __os, const _Tp& __x)
      |     ^~~~~~~~
/usr/include/c++/10/ostream:773:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/ostream: In substitution of ‘template<class _Ostream, class _Tp> typename std::enable_if<std::__and_<std::__not_<std::is_lvalue_reference<_Tp> >, std::__is_convertible_to_basic_ostream<_Ostream>, std::__is_insertable<typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type, const _Tp&, void> >::value, typename std::__is_convertible_to_basic_ostream<_Tp>::__ostream_type>::type std::operator<<(_Ostream&&, const _Tp&) [with _Ostream = std::basic_ostream<char>&; _Tp = boost::any]’:
test.cpp:22:15:   required from ‘auto meth::printer(T&) [with T = boost::any]’
test.cpp:16:9:   required from ‘auto meth::input(T1&) [with T1 = boost::any]’
test.cpp:28:30:   required from here
/usr/include/c++/10/ostream:773:5: error: no type named ‘typein ‘struct std::enable_if<false, std::basic_ostream<char>&>


Сразу говорю, менять any на int, string и тд ради одного cout я не хочу.

Так вот вопрос, как вывести any type?
0
Лучшие ответы (1)
Programming
Эксперт
39485 / 9562 / 3019
Регистрация: 12.04.2006
Сообщений: 41,671
Блог
11.04.2022, 21:03
Ответы с готовыми решениями:

Как, создав переменную класса string, вывести ее последнюю букву на экран
Если нужно обратиться к определенному символу слова, то можно использовать это: string s = &quot;string&quot;; char ch = s;//contains...

Вывести переменную из другого класса
Всем привет, помогите получить ответ result в public class ProfileFragment extends Fragment для дальнейших преобразований сам же...

Как получить private переменную класса, функцей членом другого класса
Игра змейка: Есть класс поле в котором содержится размеры поля: class field { private: int FIELD_START; int...

2
Любитель чаепитий
 Аватар для GbaLog-
3744 / 1800 / 566
Регистрация: 24.08.2014
Сообщений: 6,018
Записей в блоге: 1
12.04.2022, 06:53
а как ты себе это представляешь?
что выводить, когда там неизвестно что лежит?
единственный вариант - это получить переменную с типом, который там внутри лежит и её уже вывести.
0
Эксперт С++
 Аватар для hoggy
8973 / 4319 / 960
Регистрация: 15.11.2014
Сообщений: 9,760
18.04.2022, 13:28
Лучший ответ Сообщение было отмечено olanro-ux как решение

Решение

Цитата Сообщение от GbaLog- Посмотреть сообщение
а как ты себе это представляешь?
что выводить, когда там неизвестно что лежит?
std::any прекрасно знает, что у него там лежит.
в его основе лежит идиома type erasure
к сожалению, из коробки вывод в поток не предусмотрен.

Цитата Сообщение от olanro-ux Посмотреть сообщение
как вывести any type?
можно задействовать type erasure,
и просто доработать недостающую функциональность:

https://rextester.com/MNIL91254

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cassert>
#include <any>
 
struct iout
{
    virtual ~iout(){}
    virtual std::ostream& out(std::ostream& out, const std::any& data) const = 0;
};
 
template<class t>
struct tout: iout
{
    virtual std::ostream& out(std::ostream& out, const std::any& data) const override
    {
        const auto p = std::any_cast<const t>(&data);
        assert(p);
        out << *p << '\n';
        return out;
    }
};
 
struct meth 
{
    std::any console;
    char type_erasure[sizeof(iout)];
    
    meth(): console(), type_erasure() {}
    
    template<typename t> void emplace(t&& src) 
    {
        console = std::forward<t>(src);
        new (type_erasure) tout<t>();
    }
    
    template<typename t, size_t n> void emplace(t (&src)[n]) 
    {
        console = std::string(src);
        new (type_erasure) tout<std::string>();
    }
    
    void print() const
    {
        assert(console.has_value());
        const iout* view = reinterpret_cast<const iout*>(type_erasure);
        assert(view);
        view->out(std::cout, console);
    }
};
 
int main() 
{
    meth methode;
    
    methode.emplace(33);
    methode.print();
    
    methode.emplace(true);
    methode.print();
    
    methode.emplace("hello");
    methode.print();    
}
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
inter-admin
Эксперт
29715 / 6470 / 2152
Регистрация: 06.03.2009
Сообщений: 28,500
Блог
18.04.2022, 13:28
Помогаю со студенческими работами здесь

Не могу вывести в TextBox переменную Int из другого класса
Не могу вывести в TextBox переменную Int из другого класса using System; using System.Collections.Generic; using...

Как задасть значение Textbox в переменную, а затем эту переменную вывести в другой форме
Приветствую Есть форма с полем, где есть значение, как значение этого поле перенести в переменную, а затем вывести ее в другом поле,...

Как вывести переменную с сайта на php в переменную C# в Unity?
Например, где то на сайте есть такая страница &lt;? session_start(); $login = $_SESSION; echo &quot;$login&quot;; ?&gt; Как мне...

Как в VB сделать статическую переменную класса?
Всем привет, 1) Можно ли в VB сделать некоторую переменную единой для всех классов? Допустим, у меня несколько объектов того же...

Как сделать переменную св-вом класса
CustomGLWidget::CustomGLWidget(QWidget *parent):QGLWidget(parent) { //Initialize variable members m_image =...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Опции темы

Новые блоги и статьи
POCO, ACE, Loki и другие продвинутые C++ библиотеки
NullReferenced 13.05.2025
В C++ разработки существует такое обилие библиотек, что порой кажется, будто ты заблудился в дремучем лесу. И среди этого многообразия POCO (Portable Components) – как маяк для тех, кто ищет. . .
Паттерны проектирования GoF на C#
UnmanagedCoder 13.05.2025
Вы наверняка сталкивались с ситуациями, когда код разрастается до неприличных размеров, а его поддержка становится настоящим испытанием. Именно в такие моменты на помощь приходят паттерны Gang of. . .
Создаем CLI приложение на Python с Prompt Toolkit
py-thonny 13.05.2025
Современные командные интерфейсы давно перестали быть черно-белыми текстовыми программами, которые многие помнят по старым операционным системам. CLI сегодня – это мощные, интуитивные и даже. . .
Конвейеры ETL с Apache Airflow и Python
AI_Generated 13.05.2025
ETL-конвейеры – это набор процессов, отвечающих за извлечение данных из различных источников (Extract), их преобразование в нужный формат (Transform) и загрузку в целевое хранилище (Load). . . .
Выполнение асинхронных задач в Python с asyncio
py-thonny 12.05.2025
Современный мир программирования похож на оживлённый мегаполис – тысячи процессов одновременно требуют внимания, ресурсов и времени. В этих джунглях операций возникают ситуации, когда программа. . .
Работа с gRPC сервисами на C#
UnmanagedCoder 12.05.2025
gRPC (Google Remote Procedure Call) — открытый высокопроизводительный RPC-фреймворк, изначально разработанный компанией Google. Он отличается от традиционых REST-сервисов как минимум тем, что. . .
CQRS (Command Query Responsibility Segregation) на Java
Javaican 12.05.2025
CQRS — Command Query Responsibility Segregation, или разделение ответственности команд и запросов. Суть этого архитектурного паттерна проста: операции чтения данных (запросы) отделяются от операций. . .
Шаблоны и приёмы реализации DDD на C#
stackOverflow 12.05.2025
Когда я впервые погрузился в мир Domain-Driven Design, мне показалось, что это очередная модная методология, которая скоро канет в лету. Однако годы практики убедили меня в обратном. DDD — не просто. . .
Исследование рантаймов контейнеров Docker, containerd и rkt
Mr. Docker 11.05.2025
Когда мы говорим о контейнерных рантаймах, мы обсуждаем программные компоненты, отвечающие за исполнение контейнеризованных приложений. Это тот слой, который берет образ контейнера и превращает его в. . .
Micronaut и GraalVM - будущее микросервисов на Java?
Javaican 11.05.2025
Облачные вычисления безжалостно обнажили ахиллесову пяту Java — прожорливость к ресурсам и медлительный старт приложений. Традиционные фреймворки, годами радовавшие корпоративных разработчиков своей. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2025, CyberForum.ru