Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.60/5: Рейтинг темы: голосов - 5, средняя оценка - 4.60
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562

Не понятный амбигус

25.12.2012, 12:00. Показов 1143. Ответов 14
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
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
//=================================================================================================
namespace Longs
{
 class TInteger;
};
//=================================================================================================
class Longs::TInteger
{
//-------------------------------------------------------------------------------------------------
  protected:
//-------------------------------------------------------------------------------------------------
  uint8_t       Data[0x100]; /*Данные числа в дополнительном коде, порядок - старший в младшем*/
//-------------------------------------------------------------------------------------------------
 public    :
 //-------------------------------------------------------------------------------------------------
                TInteger         (                   );
                TInteger         (TInteger     &Value);
                TInteger         (int16_t       Value);
                TInteger         (int32_t       Value);
//-------------------------------------------------------------------------------------------------
               ~TInteger         (                   );
//-------------------------------------------------------------------------------------------------
  TInteger      operator =       (TInteger     &Right);
  TInteger      operator =       (int16_t       Value);
  TInteger      operator =       (int32_t       Value);
//-------------------------------------------------------------------------------------------------
  TInteger      operator +       (TInteger      Right);
  TInteger      operator -       (TInteger     &Right);
  TInteger      operator *       (TInteger     &Right);
  TInteger      operator /       (TInteger     &Right);
  TInteger      operator %       (TInteger     &Right);
//-------------------------------------------------------------------------------------------------
  TInteger      operator +=      (TInteger     &Right);
  TInteger      operator -=      (TInteger     &Right);
  TInteger      operator *=      (TInteger     &Right);
  TInteger      operator /=      (TInteger     &Right);
  TInteger      operator %=      (TInteger     &Right);
//-------------------------------------------------------------------------------------------------
                operator int16_t (                   );
                operator int32_t (                   );
//-------------------------------------------------------------------------------------------------
};
//=================================================================================================
int main()
{
 int32_t x32;
 int32_t y32;
 std::cin>>x32;
 Longs::TInteger x;
 Longs::TInteger y;
 Longs::TInteger z;
 std::cin>>x32;
 std::cin>>y32;
 x=x32;
 y=y32;
 z=x+y;
 std::cout<<"out"<<std::endl;
 std::cout<<(int32_t)x;
}
. Пишет:
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp||In function 'int main()':|
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp|15|error: ambiguous overload for 'operator=' in 'z = Longs::TInteger::operator+(Longs::TInteg er)(Longs::TInteger(((Longs::TInteger&)( & y))))'|
C:\tsserver\Projects\cpp\codeblocks\Long s\integer.hpp|120|note: candidates are: Longs::TInteger Longs::TInteger::operator=(int16_t)|
C:\tsserver\Projects\cpp\codeblocks\Long s\integer.hpp|138|note: Longs::TInteger Longs::TInteger::operator=(int32_t)|
||=== Build finished: 1 errors, 0 warnings ===|
. Если заменить
C++
1
 z=x+y;
на
C++
1
 x+y;
или на
C++
1
 z=x;
, то эйси.
0
IT_Exp
Эксперт
34794 / 4073 / 2104
Регистрация: 17.06.2006
Сообщений: 32,602
Блог
25.12.2012, 12:00
Ответы с готовыми решениями:

Амбигус между char и bool
на строку Stream&lt;&lt;*p;, где char *p;, выше std::ofstream &amp;operator &lt;&lt; ( ...

Не понятный цикл
Функция возвращает otv1. В barr_code хранятся значения битов(нули и единицы). Что делает цикл? int barr_code; int otv=0, mn=1; ...

Не понятный глюк с cout
Дня доброго Есть небольшая програмулина #include&lt;iostream&gt; #include&lt;string&gt; #include&lt;iomanip&gt; using namespace std; class...

14
Модератор
 Аватар для vxg
3406 / 2177 / 354
Регистрация: 13.01.2012
Сообщений: 8,444
25.12.2012, 14:18
определены конструкторы получающие объект из 16 и 32 и операторы присваивания из них же. нужно сделать конструкторы 16 и 32 explicit... мб)
0
What a waste!
 Аватар для gray_fox
1610 / 1302 / 180
Регистрация: 21.04.2012
Сообщений: 2,733
25.12.2012, 14:24
Есть операторы преобразования в int_16 и int_32 и операторы присваивания с теми же типами. Он просто не знает, к чему преобразовывать, т.к. обе ситуации равнозначны. Попробуй определи конструктор копирования. Или избавься от операторов преобразования (хотя бы от одного из них).
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
25.12.2012, 16:10  [ТС]
Цитата Сообщение от gray_fox Посмотреть сообщение
Он просто не знает, к чему преобразовывать,
А зачем преобразовывать? Есть же версия, принимающая непосредственно объект.

Добавлено через 34 секунды
Цитата Сообщение от gray_fox Посмотреть сообщение
Попробуй определи конструктор копирования.
Он есть.

Добавлено через 16 секунд
Цитата Сообщение от gray_fox Посмотреть сообщение
Или избавься от операторов преобразования (хотя бы от одного из них).
Нельзя.

Добавлено через 5 минут
Проблема решена так:
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
class Longs::TInteger
{
//-------------------------------------------------------------------------------------------------
  protected:
//-------------------------------------------------------------------------------------------------
  uint8_t       Data[0x100]; //This is the number. The byte order is little-endian.
//-------------------------------------------------------------------------------------------------
 public    :
//-------------------------------------------------------------------------------------------------
                TInteger         (                         );
                TInteger         (const TInteger     &Value);
                TInteger         (const int16_t       Value);
                TInteger         (const int32_t       Value);
//-------------------------------------------------------------------------------------------------
               ~TInteger         (                         );
//-------------------------------------------------------------------------------------------------
  TInteger      operator =       (const TInteger     &Right);
  TInteger      operator =       (const int16_t       Right);
  TInteger      operator =       (const int32_t       Right);
//-------------------------------------------------------------------------------------------------
  TInteger      operator +       (const TInteger     &Right);
  TInteger      operator -       (const TInteger     &Right);
  TInteger      operator *       (const TInteger     &Right);
  TInteger      operator /       (const TInteger     &Right);
  TInteger      operator %       (const TInteger     &Right);
//-------------------------------------------------------------------------------------------------
  TInteger      operator +=      (const TInteger     &Right);
  TInteger      operator -=      (const TInteger     &Right);
  TInteger      operator *=      (const TInteger     &Right);
  TInteger      operator /=      (const TInteger     &Right);
  TInteger      operator %=      (const TInteger     &Right);
//-------------------------------------------------------------------------------------------------
                operator int16_t (                         );
                operator int32_t (                         );
//-------------------------------------------------------------------------------------------------
};
. Но не понятно, почему без конста имбигус, а с ним эйси.
0
What a waste!
 Аватар для gray_fox
1610 / 1302 / 180
Регистрация: 21.04.2012
Сообщений: 2,733
25.12.2012, 16:23
Цитата Сообщение от taras atavin Посмотреть сообщение
Он есть.
У тебя его не было (TInteger(TInteger const&)). Хотя конечно нужен был оператор присвоения, а не конструктор, моя ошибка, но не суть, его тоже не было)
Цитата Сообщение от taras atavin Посмотреть сообщение
А зачем преобразовывать
Цитата Сообщение от taras atavin Посмотреть сообщение
x+y
возвращает временный объект, оператора присвоения из TInteger или TInteger const& тоже, поэтому оставалось только TInteger -> operator int_16() -> operator =(int_16) или TInteger -> operator int_32() -> operator =(int_32) .

Добавлено через 46 секунд
Цитата Сообщение от taras atavin Посмотреть сообщение
Но не понятно, почему без конста имбигус, а с ним эйси.
Потому что к неконстантной ссыле не привяжешь временный объект.
1
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
25.12.2012, 16:43  [ТС]
Цитата Сообщение от gray_fox Посмотреть сообщение
У тебя его не было (TInteger(TInteger const&))
Читай:
Цитата Сообщение от taras atavin Посмотреть сообщение
C++
1
2
3
4
5
6
public:
//-------------------------------------------------------------------------------------------------
TInteger ();
TInteger (TInteger &Value);
TInteger (int16_t Value);
TInteger (int32_t Value);
Добавлено через 2 минуты
Цитата Сообщение от gray_fox Посмотреть сообщение
а не конструктор, моя ошибка, но не суть, его тоже не было)
Тоже был.
0
go
Эксперт С++
3646 / 1378 / 243
Регистрация: 16.04.2009
Сообщений: 4,526
25.12.2012, 22:09
Цитата Сообщение от taras atavin Посмотреть сообщение
TInteger * * *operator = * * * (TInteger * * &Right);
Этот оператор не правильно определен, т.к. этот определен именно так
Цитата Сообщение от taras atavin Посмотреть сообщение
TInteger * * *operator + * * * (TInteger * * *Right);
Как вариант возвращать ссылку.

Добавлено через 1 минуту
Цитата Сообщение от go Посмотреть сообщение
Как вариант возвращать ссылку.
Но это не логично. Лучше корректировать оператор =

Добавлено через 5 минут
Цитата Сообщение от go Посмотреть сообщение
Лучше корректировать оператор =
Например константная ссылка.
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
26.12.2012, 07:19  [ТС]
Цитата Сообщение от go Посмотреть сообщение
Как вариант возвращать ссылку.
На локальный объект?

Добавлено через 37 секунд
Цитата Сообщение от go Посмотреть сообщение
Лучше корректировать оператор =
Я пробовал убрать ссылку. Не помогало.
0
go
Эксперт С++
3646 / 1378 / 243
Регистрация: 16.04.2009
Сообщений: 4,526
26.12.2012, 18:37
Цитата Сообщение от taras atavin Посмотреть сообщение
Я пробовал убрать ссылку. Не помогало.
Покажи как и какие ошибки.
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
26.12.2012, 18:43  [ТС]
Ошибка в стартовом посте.
0
go
Эксперт С++
3646 / 1378 / 243
Регистрация: 16.04.2009
Сообщений: 4,526
26.12.2012, 19:41
taras atavin, переделайте. Вот так
C++
1
TInteger      operator =       (TInteger     Right);
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
26.12.2012, 19:46  [ТС]
Пищу же, что пробовал, не помогло. Амбигус только с кнонстом прошёл.
0
go
Эксперт С++
3646 / 1378 / 243
Регистрация: 16.04.2009
Сообщений: 4,526
26.12.2012, 20:05
Цитата Сообщение от taras atavin Посмотреть сообщение
Амбигус только с кнонстом прошёл.
Что вы пишете. Я Вам явно указал, или добавить модификатор const, или убрать ссылку. Неужели не помогает ни одно?
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
26.12.2012, 20:07  [ТС]
Цитата Сообщение от go Посмотреть сообщение
Неужели не помогает ни одно?
только одно.
0
 Аватар для taras atavin
4226 / 1796 / 211
Регистрация: 24.11.2009
Сообщений: 27,562
28.12.2012, 11:50  [ТС]
Опять амбигус, теперь в другом операторе.
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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#ifndef INTEGERLONGS_HPP_INCLUDED
#define INTEGERLONGS_HPP_INCLUDED
//=====================================================================================================================================================================================================
#include <iostream>
//=====================================================================================================================================================================================================
namespace Longs
{
 class TInteger;
};
//=====================================================================================================================================================================================================
class Longs::TInteger
{
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 protected:
 public   :
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  uint8_t       Data[0x100]; //This is the number. The encoding is additional code. The byte order is little-endian.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 public   :
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                TInteger         (                             );
                TInteger         (const        TInteger &Value );
                TInteger         (const        int16_t   Value );
                TInteger         (const        int32_t   Value );
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
               ~TInteger         (                             );
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  TInteger      operator =       (const        TInteger &Right );
  TInteger      operator =       (const        int16_t   Right );
  TInteger      operator =       (const        int32_t   Right );
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  TInteger      operator -       (                             ) const;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  TInteger      operator +       (const        TInteger &Right ) const;
  TInteger      operator -       (const        TInteger &Right ) const;
  TInteger      operator *       (const        TInteger &Right ) const;
  TInteger      operator /       (const        TInteger &Right ) const;
  TInteger      operator %       (const        TInteger &Right ) const;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  TInteger      operator +=      (const        TInteger &Right );
  TInteger      operator -=      (const        TInteger &Right );
  TInteger      operator *=      (const        TInteger &Right );
  TInteger      operator /=      (const        TInteger &Right );
  TInteger      operator %=      (const        TInteger &Right );
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                operator int16_t (                             ) const;
                operator int32_t (                             ) const;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  friend
  std::ostream &operator <<      (      std  ::ostream  &Stream,
                                  const Longs::TInteger &Value );
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
};
//=====================================================================================================================================================================================================
Longs       ::
TInteger    ::  TInteger         (                             )
{
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    ::  TInteger         (const        TInteger &Value )
{
 const uint8_t *Source;
       uint8_t *Target;
 for (Source=Value.Data+0xFF, Target=Data+0xFF; Target>=Data; --Source, --Target)
 {
  *Target=*Source;
 }
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    ::  TInteger         (const        int16_t   Value )
{
 uint8_t *p;
 uint8_t  Buffer;
 *(Data+0xFE)=(uint8_t)((Value&0xFF00)>>8);
 *(Data+0xFF)=(uint8_t) (Value&0x00FF);
 Buffer=0xFF*((uint8_t)((Value&0x8000)>>15));
 for (p=Data+0xFD; p>=Data; --p)
 {
  *p=Buffer;
 }
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    ::  TInteger         (const        int32_t   Value )
{
 uint8_t *p;
 uint8_t  Buffer;
 *(Data+0xFC)=(uint8_t)((Value&0xFF000000)>>24);
 *(Data+0xFD)=(uint8_t)((Value&0x00FF0000)>>16);
 *(Data+0xFE)=(uint8_t)((Value&0x0000FF00)>>8 );
 *(Data+0xFF)=(uint8_t) (Value&0x000000FF);
 Buffer=0xFF*((uint8_t)((Value&0x80000000)>>31));
 for (p=Data+0xFB; p>=Data; --p)
 {
  *p=Buffer;
 }
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    :: ~TInteger         (                          )
{
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator =       (const        TInteger &Right )
{
 const uint8_t *Source;
       uint8_t *Target;
 for (Source=Right.Data+0xFF, Target=Data+0xFF; Target>=Data; --Source, --Target)
 {
  *Target=*Source;
 }
 return *this;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator =       (const        int16_t   Right )
{
 uint8_t *p;
 uint8_t  Buffer;
 *(Data+0xFE)=(uint8_t)((Right&0xFF00)>>8);
 *(Data+0xFF)=(uint8_t) (Right&0x00FF);
 Buffer=0xFF*((uint8_t)((Right&0x8000)>>15));
 for (p=Data+0xFD; p>=Data; --p)
 {
  *p=Buffer;
 }
 return *this;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator =       (const        int32_t   Right )
{
 uint8_t *p;
 uint8_t  Buffer;
 *(Data+0xFC)=(uint8_t)((Right&0xFF000000)>>24);
 *(Data+0xFD)=(uint8_t)((Right&0x00FF0000)>>16);
 *(Data+0xFE)=(uint8_t)((Right&0x0000FF00)>>8 );
 *(Data+0xFF)=(uint8_t) (Right&0x000000FF);
 Buffer=0xFF*((uint8_t)((Right&0x80000000)>>31));
 for (p=Data+0xFB; p>=Data; --p)
 {
  *p=Buffer;
 }
 return *this;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator -       (                             ) const
{
 const uint8_t  *Source;
       uint8_t  *Target;
       uint16_t  Buffer;
       uint16_t  Carry;
       TInteger  Result;
 for (Source=Data+0xFF, Target=Result.Data+0xFF; Source>=Data; --Source, --Target)
 {
  *Target=~(*Source);
 }
 for (Carry=0x0001, Target=Result.Data+0xFF; Target>=Result.Data; --Target)
 {
   Buffer=((uint16_t)*Target)+Carry;
  *Target= (uint8_t )(Buffer&0x00FF);
  Carry=(Buffer&0xFF00)>>8;
 }
 return Result;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator +       (const        TInteger &Right ) const
{
 const uint8_t  *LeftByte;
 const uint8_t  *RightByte;
       uint8_t  *ResultByte;
       uint16_t  Buffer;
       uint16_t  Carry;
       TInteger  Result;
 for (Carry=0x0000, LeftByte=Data+0xFF, RightByte=Right.Data+0xFF, ResultByte=Result.Data+0xFF; LeftByte>=Data; --LeftByte, --RightByte, --ResultByte)
 {
   Buffer    =((uint16_t)*LeftByte)+((uint16_t)*RightByte)+Carry;
  *ResultByte= (uint8_t )(Buffer&0x00FF);
  Carry=(Buffer&0xFF00)>>8;
 }
 return Result;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator -       (const        TInteger &Right ) const
{
 const uint8_t  *LeftByte;
 const uint8_t  *RightByte;
       uint8_t  *ResultByte;
       uint16_t  Buffer;
       uint16_t  Carry;
       TInteger  Result;
 for (Carry=0x0000, LeftByte=Data+0xFF, RightByte=Right.Data+0xFF, ResultByte=Result.Data+0xFF; LeftByte>=Data; --LeftByte, --RightByte, --ResultByte)
 {
   Buffer    =((uint16_t)*LeftByte)-((uint16_t)*RightByte)-Carry;
  *ResultByte= (uint8_t )(Buffer&0x00FF);
  Carry=(Buffer&0x0100)>>8;
 }
 return Result;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger
Longs       ::
TInteger    ::  operator *       (const        TInteger &Right ) const
{
 const uint8_t  *LeftByte;
 const uint8_t  *RightByte;
       uint8_t  *ResultByte;
       uint8_t  *ResultStart;
       uint16_t  Buffer;
       uint16_t  Carry;
       TInteger  Result;
       TInteger  LeftBuffer;
       TInteger  RightBuffer;
 if (((*Data)&0x80)==0x80)
 {
  LeftBuffer=-(*this);
 }
 else
 {
  LeftBuffer=*this;
 }
 if (((*(Right.Data))&0x80)==0x80)
 {
  RightBuffer=-Right;
 }
 else
 {
  RightBuffer=Right;
 }
 for (ResultByte=Result.Data+0xFF; ResultByte>=Result.Data; --ResultByte)
 {
  *ResultByte=0;
 }
 for (LeftByte=LeftBuffer.Data+0xFF, ResultStart=Result.Data+0xFF; (LeftByte>=LeftBuffer.Data)&&(ResultStart>=Result.Data); --LeftByte, --ResultStart)
 {
  for (Carry=0x0000, RightByte=RightBuffer.Data+0xFF, ResultByte=ResultStart; (RightByte>=RightBuffer.Data)&&(ResultByte>=Result.Data); --RightByte, --ResultByte)
  {
   Buffer    =((uint16_t)*LeftByte)*((uint16_t)*RightByte)+((uint16_t)*ResultByte)+Carry;
  *ResultByte= (uint8_t )(Buffer&0x00FF);
   Carry=(Buffer&0xFF00)>>8;Carry=(Buffer&0xFF00)>>8;
  }
 }
 if ((((*Data)&0x80)^((*(Right.Data))&0x80))==0x80)
 {
  return -Result;
 }
 return Result;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    ::  operator int16_t (                             ) const
{
 return (((uint16_t)((* Data)&0x80))<<8)|(((uint16_t)((*(Data+0xFE))&0x7F))<<8)|((uint16_t)(*(Data+0xFF)));
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Longs       ::
TInteger    ::  operator int32_t (                             ) const
{
 return (((uint32_t)((*Data)&0x80))<<24)|(((uint32_t)((*(Data+0xFC))&0x7F))<<24)|(((uint32_t)((*(Data+0xFD))&0xFF))<<16)|(((uint32_t)((*(Data+0xFE))&0xFF))<<8)|((uint32_t)(*(Data+0xFF)));
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
std::ostream   &operator <<      (      std  ::ostream  &Stream,
                                  const Longs::TInteger &Value )
{
 static const char Digits[0x100][0x3]={"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B","0C", "0D", "0E", "0F",
                                       "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B","1C", "1D", "1E", "1F",
                                       "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B","2C", "2D", "2E", "2F",
                                       "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B","3C", "3D", "3E", "3F",
                                       "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B","4C", "4D", "4E", "4F",
                                       "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B","5C", "5D", "5E", "5F",
                                       "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B","6C", "6D", "6E", "6F",
                                       "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B","7C", "7D", "7E", "7F",
                                       "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B","8C", "8D", "8E", "8F",
                                       "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B","9C", "9D", "9E", "9F",
                                       "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB","AC", "AD", "AE", "AF",
                                       "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB","BC", "BD", "BE", "BF",
                                       "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB","CC", "CD", "CE", "CF",
                                       "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB","DC", "DD", "DE", "DF",
                                       "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB","EC", "ED", "EE", "EF",
                                       "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB","FC", "FD", "FE", "FF"};
 const uint8_t *p;
 const uint8_t *End;
 for (p=Value.Data, End=Value.Data+0xFF; p<=End; ++p)
 {
  Stream<<Digits[*p];
 }
 return Stream;
}
//=====================================================================================================================================================================================================
#endif // INTEGERLONGS_HPP_INCLUDED
,
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
#include <iostream>
#include <fstream>
#include "integer.hpp"
int main()
{
 std::ofstream log;
 log.open("log.txt");
 int32_t x32;
 int32_t y32;
 int32_t z32;
 Longs::TInteger x;
 Longs::TInteger y;
 Longs::TInteger z;
 for (x32=-1024; x32<=1024; ++x32)
 {
  x=x32;
  //for (y32=0; y32<=202; ++y32)
  {
   //y=y32;
   //z32=x32<<y32;
   //z=x<<y;
   log<<"x32="<<(int32_t)x32<<std::endl;
   //log<<"y32="<<(int32_t)y32<<std::endl;
   //log<<"z32="<<(int32_t)z32<<std::endl;
   log<<"x="<<x;//<<"("<<(int32_t)x<<")"<<std::endl;
   //log<<"y="<<(int32_t)y<<std::endl;
   //log<<"y="<<(int32_t)y<<std::endl;
   //log<<"z="<<(int32_t)z<<std::endl;
   //log<<"z-z32="<<((int32_t)z)-z32<<std::endl<<std::endl;
   /*if (((int32_t)z)!=z32)
   {
    std::cout<<"x32="<<(int32_t)x32<<std::endl;
    std::cout<<"y32="<<(int32_t)y32<<std::endl;
    std::cout<<"z32="<<(int32_t)z32<<std::endl;
    std::cout<<"x="<<(int32_t)x<<std::endl;
    std::cout<<"y="<<(int32_t)y<<std::endl;
    std::cout<<"y="<<(int32_t)y<<std::endl;
    std::cout<<"z="<<(int32_t)z<<std::endl;
    std::cout<<"z-z32="<<((int32_t)z)-z32<<std::endl<<std::endl;
   }*/
  }
 }
 log.close();
 return 0;
}
, пишет:
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp||In function 'int main()':|
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp|25|error: ambiguous overload for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& log.std::basic_ofstream<char, std::char_traits<char> >::<anonymous>)), ((const char*)"x=")) << x'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|108|note : candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream< _CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|117|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_Cha rT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|127|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|165|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|169|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|173|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\bits\ostream.tcc |91|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|180|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\bits\ostream.tcc |105|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|191|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|200|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|204|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|209|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|213|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|221|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|225|note : std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\bits\ostream.tcc |119|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambu f<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
C:\tsserver\Projects\cpp\codeblocks\Long s\integer.hpp|281|note: std::ostream& operator<<(std::ostream&, const Longs::TInteger&)|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|468|note : std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char) [with _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|463|note : std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char) [with _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|457|note : std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char) [with _Traits = std::char_traits<char>]|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mi ngw32\4.4.1\include\c++\ostream|451|note : std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_Char T, _Traits>&, char) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\tsserver\Projects\cpp\codeblocks\Long s\integer.hpp|50|note: std::ostream& Longs::operator<<(std::ostream&, const Longs::TInteger&)|
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp|9|warning: unused variable 'y32'|
C:\tsserver\Projects\cpp\codeblocks\Long s\Test.cpp|10|warning: unused variable 'z32'|
||=== Build finished: 1 errors, 2 warnings ===|
.
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
BasicMan
Эксперт
29316 / 5623 / 2384
Регистрация: 17.02.2009
Сообщений: 30,364
Блог
28.12.2012, 11:50
Помогаю со студенческими работами здесь

Не понятный вызов деструктора
Здравствуйте. Ситуация такая, есть класс MyClass к примеру, и при таком коде: //разные инклюды MyClass var; int WinMain(...) { ...

Корешки-вершки квадратные, не понятный вывод
В чем проблема собстна? #include &lt;iostream&gt; using namespace std; int main() { setlocale(LC_ALL,...

Не понятный дополнительный символ в конце файла
Друзья помогите пож-та разобраться с проблемой. Ниже простой пример посимвольного считывания из файла # include &lt;fstream&gt; #...

Не понятный глюк вызова перегруженной функции
void f (std::wfstream&amp;, bool, const char*, size_t , size_t); void f (std::wfstream&amp;, int, const char*, size_t , size_t); void f ...

Ищу понятный учебник C++ с привязкой к IDE Visual Studio
Добрый вечер, я изучаю Visual Basic net и он дается мне достаточно легко. Изучал я его используя IDE Visual Studio 2010. Хочу начат изучать...


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

Или воспользуйтесь поиском по форуму:
15
Ответ Создать тему
Новые блоги и статьи
Кто-нибудь знает, где можно бесплатно получить настольный компьютер или ноутбук? США.
Programma_Boinc 26.12.2025
Кто-нибудь знает, где можно бесплатно получить настольный компьютер или ноутбук? США. Нашел на реддите интересную статью под названием «Кто-нибудь знает, где получить бесплатный компьютер или. . .
Thinkpad X220 Tablet — это лучший бюджетный ноутбук для учёбы, точка.
Programma_Boinc 23.12.2025
Рецензия / Мнение/ Перевод Нашел на реддите интересную статью под названием The Thinkpad X220 Tablet is the best budget school laptop period . Ниже её машинный перевод. Thinkpad X220 Tablet —. . .
PhpStorm 2025.3: WSL Terminal всегда стартует в ~
and_y87 14.12.2025
PhpStorm 2025. 3: WSL Terminal всегда стартует в ~ (home), игнорируя директорию проекта Симптом: После обновления до PhpStorm 2025. 3 встроенный терминал WSL открывается в домашней директории. . .
Как объединить две одинаковые БД Access с разными данными
VikBal 11.12.2025
Помогите пожалуйста !! Как объединить 2 одинаковые БД Access с разными данными.
Новый ноутбук
volvo 07.12.2025
Всем привет. По скидке в "черную пятницу" взял себе новый ноутбук Lenovo ThinkBook 16 G7 на Амазоне: Ryzen 5 7533HS 64 Gb DDR5 1Tb NVMe 16" Full HD Display Win11 Pro
Музыка, написанная Искусственным Интеллектом
volvo 04.12.2025
Всем привет. Некоторое время назад меня заинтересовало, что уже умеет ИИ в плане написания музыки для песен, и, собственно, исполнения этих самых песен. Стихов у нас много, уже вышли 4 книги, еще 3. . .
От async/await к виртуальным потокам в Python
IndentationError 23.11.2025
Армин Ронахер поставил под сомнение async/ await. Создатель Flask заявляет: цветные функции - провал, виртуальные потоки - решение. Не threading-динозавры, а новое поколение лёгких потоков. Откат?. . .
Поиск "дружественных имён" СОМ портов
Argus19 22.11.2025
Поиск "дружественных имён" СОМ портов На странице: https:/ / norseev. ru/ 2018/ 01/ 04/ comportlist_windows/ нашёл схожую тему. Там приведён код на С++, который показывает только имена СОМ портов, типа,. . .
Сколько Государство потратило денег на меня, обеспечивая инсулином.
Programma_Boinc 20.11.2025
Сколько Государство потратило денег на меня, обеспечивая инсулином. Вот решила сделать интересный приблизительный подсчет, сколько государство потратило на меня денег на покупку инсулинов. . . .
Ломающие изменения в C#.NStar Alpha
Etyuhibosecyu 20.11.2025
Уже можно не только тестировать, но и пользоваться C#. NStar - писать оконные приложения, содержащие надписи, кнопки, текстовые поля и даже изображения, например, моя игра "Три в ряд" написана на этом. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2025, CyberForum.ru