www.digitalmars.com         C & C++   DMDScript  

c++.wxwindows - error in recent dmc

reply chris elliott <biol75 york.ac.uk> writes:
I got this with a recent (843.6n) dmc, but it was ok in about 834/835

Is this a bug, or something wrong in the wxWidgets code  (code based on 
oleutils.h)

chris


C:\compiler>dmc -mn -c  -g -o+none -Ar -Ae -H -HO- dmc_test.cpp
dmc_test.cpp(9) : Error: reference must refer to same type or be const
Had: int
and: int &
{
^
dmc_test.cpp(18) : Error: '=', ';' or ',' expected
}
^
dmc_test.cpp(20) : Error: identifier or '( declarator )' expected
--- errorlevel 1



dmc_test.cpp:

#define ULONG int

class wxAutoULong
{
public:
     wxAutoULong(ULONG value = 0) : m_Value(value) { }

     operator ULONG&() { return m_Value; }
     ULONG& operator=(ULONG value) { return m_Value = value; }

  private:
     ULONG m_Value;
};

wxAutoULong A, B ;

int main
{
     A=B;
}
Jun 01 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"chris elliott" <biol75 york.ac.uk> wrote in message
news:d7kk7t$1uld$1 digitaldaemon.com...
      ULONG& operator=(ULONG value) { return m_Value = value; }
This is the problem line, it tries to convert: return m_Value=value; into a reference. But it isn't a reference, it's an assignment expression. Rewrite as: m_Value = value; return m_Value;
Jun 01 2005
next sibling parent chris elliott <biol75 york.ac.uk> writes:
thank you for the clear explanation
chris

Walter wrote:
 "chris elliott" <biol75 york.ac.uk> wrote in message
 news:d7kk7t$1uld$1 digitaldaemon.com...
 
     ULONG& operator=(ULONG value) { return m_Value = value; }
This is the problem line, it tries to convert: return m_Value=value; into a reference. But it isn't a reference, it's an assignment expression. Rewrite as: m_Value = value; return m_Value;
Jun 02 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Walter" <newshound digitalmars.com> wrote in message
news:d7lfbj$2nmg$1 digitaldaemon.com...
 "chris elliott" <biol75 york.ac.uk> wrote in message
 news:d7kk7t$1uld$1 digitaldaemon.com...
      ULONG& operator=(ULONG value) { return m_Value = value; }
This is the problem line, it tries to convert: return m_Value=value; into a reference. But it isn't a reference, it's an assignment expression. Rewrite as: m_Value = value; return m_Value;
I forgot to mention, the reason it "worked" before was the compiler rewrote the code as: tmp = (m_Value = value); return tmp; This is no longer in conformance with the C++ Standard, so was removed.
Jun 02 2005
parent reply chris elliott <biol75 york.ac.uk> writes:
Walter wrote:
 "Walter" <newshound digitalmars.com> wrote in message
 news:d7lfbj$2nmg$1 digitaldaemon.com...
 
"chris elliott" <biol75 york.ac.uk> wrote in message
news:d7kk7t$1uld$1 digitaldaemon.com...

     ULONG& operator=(ULONG value) { return m_Value = value; }
This is the problem line, it tries to convert: return m_Value=value; into a reference. But it isn't a reference, it's an assignment expression. Rewrite as: m_Value = value; return m_Value;
I forgot to mention, the reason it "worked" before was the compiler rewrote the code as: tmp = (m_Value = value); return tmp; This is no longer in conformance with the C++ Standard, so was removed.
thanks, the code also "works" with VC, Borland, watcom compilers (and I guess gcc) chris
Jun 03 2005
parent chris elliott <biol75 york.ac.uk> writes:
chris elliott wrote:
 
 
I forgot to say, how good it is to have dm spot such code bugs !Thanks again for all the rapid support

 thanks, the code also "works" with VC, Borland, watcom compilers (and I 
 guess gcc)
 
 chris
Jun 03 2005