Форум программистов, компьютерный форум CyberForum.ru

Не работает friend - C++

Восстановить пароль Регистрация
 
taras atavin
Ушёл с форума.
 Аватар для taras atavin
3569 / 1752 / 91
Регистрация: 24.11.2009
Сообщений: 27,619
28.12.2012, 11:17     Не работает friend #1
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
#ifndef INTEGERLONGS_HPP_INCLUDED
#define INTEGERLONGS_HPP_INCLUDED
//=====================================================================================================================================================================================================
#include <iostream>
//=====================================================================================================================================================================================================
namespace Longs
{
 class TInteger;
};
//=====================================================================================================================================================================================================
class Longs::TInteger
{
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 protected:
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  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[*(uint8_t*)p];
 }
 return Stream;
}
//=====================================================================================================================================================================================================
#endif // INTEGERLONGS_HPP_INCLUDED
, ругается на конец
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp||In function 'std::ostream operator<<(std::ostream&, const Longs::TInteger&)':|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|16|error: 'uint8_t Longs::TInteger:ata [256]' is protected|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|301|error: within this context|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|16|error: 'uint8_t Longs::TInteger:ata [256]' is protected|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|301|error: within this context|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\ios_base.h|790|error: 'std::ios_base::ios_base(const std::ios_base&)' is private|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|47|error: within this context|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|56|note: synthesized method 'std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)' first required here |
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp||In function 'std::ostream operator<<(std::ostream&, const Longs::TInteger&)':|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|305|note: synthesized method 'std::basic_ostream<char, std::char_traits<char> >::basic_ostream(const std::basic_ostream<char, std::char_traits<char> >&)' first required here |
C:\tsserver\Projects\cpp\codeblocks\Longs\Test.cpp||In function 'int main()':|
C:\tsserver\Projects\cpp\codeblocks\Longs\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\mingw32\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\mingw32\4.4.1\include\c++\ostream|117|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\4.4.1\include\c++\bits\ostream.tcc|119|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|280|note: std::ostream operator<<(std::ostream&, const Longs::TInteger&)|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\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\mingw32\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\mingw32\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\mingw32\4.4.1\include\c++\ostream|451|note: std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|49|note: std::ostream Longs::operator<<(std::ostream&, const Longs::TInteger&)|
C:\tsserver\Projects\cpp\codeblocks\Longs\Test.cpp|9|warning: unused variable 'y32'|
C:\tsserver\Projects\cpp\codeblocks\Longs\Test.cpp|10|warning: unused variable 'z32'|
||=== Build finished: 7 errors, 2 warnings ===|
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
28.12.2012, 11:17     Не работает friend
Посмотрите здесь:

Friend Function C++
Friend класса C++
friend function C++
C++ friend классы
friend class C++
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
gray_fox
What a waste!
 Аватар для gray_fox
1244 / 1127 / 53
Регистрация: 21.04.2012
Сообщений: 2,350
Завершенные тесты: 3
28.12.2012, 11:49     Не работает friend #2
Цитата Сообщение от taras atavin Посмотреть сообщение
C++
1
std::ostream operator << ( std ::ostream &Stream, const Longs::TInteger &Value );
Надо ссылку возвращать - потоки нельзя копировать.
Toshkarik
 Аватар для Toshkarik
1139 / 856 / 50
Регистрация: 03.08.2011
Сообщений: 2,381
Завершенные тесты: 1
28.12.2012, 11:51     Не работает friend #3
taras atavin, оператор должен возвращать ссылку на объект.
C++
1
std::ostream &operator<<( std::ostream &, ...
taras atavin
Ушёл с форума.
 Аватар для taras atavin
3569 / 1752 / 91
Регистрация: 24.11.2009
Сообщений: 27,619
28.12.2012, 11:52  [ТС]     Не работает friend #4
А тогда амбигус:
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\Longs\Test.cpp||In function 'int main()':|
C:\tsserver\Projects\cpp\codeblocks\Longs\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\mingw32\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\mingw32\4.4.1\include\c++\ostream|117|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\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\mingw32\4.4.1\include\c++\bits\ostream.tcc|119|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|281|note: std::ostream& operator<<(std::ostream&, const Longs::TInteger&)|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\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\mingw32\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\mingw32\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\mingw32\4.4.1\include\c++\ostream|451|note: std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\tsserver\Projects\cpp\codeblocks\Longs\integer.hpp|50|note: std::ostream& Longs::operator<<(std::ostream&, const Longs::TInteger&)|
C:\tsserver\Projects\cpp\codeblocks\Longs\Test.cpp|9|warning: unused variable 'y32'|
C:\tsserver\Projects\cpp\codeblocks\Longs\Test.cpp|10|warning: unused variable 'z32'|
||=== Build finished: 1 errors, 2 warnings ===|
.
gray_fox
What a waste!
 Аватар для gray_fox
1244 / 1127 / 53
Регистрация: 21.04.2012
Сообщений: 2,350
Завершенные тесты: 3
28.12.2012, 11:57     Не работает friend #5
Наверняка опять проблемы из-за операторов приведения к целому.
rangerx
1908 / 1517 / 139
Регистрация: 31.05.2009
Сообщений: 2,876
28.12.2012, 11:59     Не работает friend #6
1) оператор вывода должен возвращать ссылку на ostream.
2) опиши friend функцию внутри пространства имён Longs.
taras atavin
Ушёл с форума.
 Аватар для taras atavin
3569 / 1752 / 91
Регистрация: 24.11.2009
Сообщений: 27,619
28.12.2012, 12:00  [ТС]     Не работает friend #7
А почему они то мешают? Ведь есть версия, к которой приводить вроде как не надо.

Добавлено через 59 секунд
Цитата Сообщение от rangerx Посмотреть сообщение
опиши friend функцию внутри пространства имён Longs.
А ничего, что прототип валяется в фигурных скобках члена этого пространства?
MoreAnswers
Эксперт
37091 / 29110 / 5898
Регистрация: 17.06.2006
Сообщений: 43,301
28.12.2012, 12:15     Не работает friend
Еще ссылки по теме:

Объясните, как в данном примере работает friend C++
C++ класс Friend
Friend function C++

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

Или воспользуйтесь поиском по форуму:
rangerx
1908 / 1517 / 139
Регистрация: 31.05.2009
Сообщений: 2,876
28.12.2012, 12:15     Не работает friend #8
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
namespace Longs 
{
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[*(uint8_t*)p];
 }
 return Stream;
}
}
Yandex
Объявления
28.12.2012, 12:15     Не работает friend
Ответ Создать тему
Опции темы

Текущее время: 23:58. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru