This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: egcs-1.1.2: overloaded ++ operator]


Ignore my previous mail.  I have fixed the problem.
The cast operator had to be a cast to a reference.
ie. "operator UINT64 ();"  was changed to "operator UINT64& ();".

Brendan.



Brendan Simon wrote:

> I have a unsigned 64 bit integer object called U64.  The following code
> example gives the following error.
>
> // **** SAMPLE CODE ****
> #include <iostream>
>
> typedef unsigned long long  UINT64;
>
> union U64
> {
>     public :
>                 U64();
>                 U64( const UINT64 newValue );
>
>                 operator UINT64 ();
>
>         U64 &   operator ++ ();
> #if 0
>         U64 &   operator ++ ( const int value );
> #endif
>     private :
>         UINT64  u64;
> };
>
> inline U64::U64()
> {
>     u64 = 0;
> }
>
> inline U64::U64( const UINT64 newValue )
> {
>     u64 = newValue;
> }
>
> inline U64::operator UINT64 ()
> {
>     return u64;
> }
>
> inline U64 & U64::operator ++ ()
> {
>     u64++;
>     return *this;
> }
>
> #if 0
> inline U64 & U64::operator ++ ( const int value )
> {
>     u64++;
>     return *this;
> }
> #endif
>
> int main( int argc, char * argv[] )
> {
>     U64 var;
>
>     var = argc;
>     cout << "var = " << var << endl;
>     var++;
>     cout << "var = " << var << endl;
>
>     return 0;
> }
>
> **** ERROR MESSAGE ****
> u64.cpp: In function `int main(int, char **)':
> u64.cpp:66: warning: no `operator ++ (int)' declared for postfix `++',
> trying prefix operator instead
> u64.cpp:66: no match for `++U64 &'
>
> If I replace the "#if 0" with "#if 1" then every thing works OK.  From
> the C++ standard I should only need the "operator ++ ();" declaration.
> Is this a problem with egcs-1.1.2 and does any one know if it works
> properly in gcc-2.95.x ?  I have not had a chance to download gcc-2.95.x
> sources and build the compiler.
>
> Thanks,
> Brendan Simon.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]