Is this legal?

J

Jim Langston

In my code I have this line:
CloseOnOpenNotifier.notifyObservers( dynamic_cast<Argument*>(
&OpenArgument( NotifyMsg ) ) );
which I'm getting a warning on in VC++ .net 2003 when I set the warning
level to 4.
c:\Source\Abyssal\source\Abyssal\CGUIElement.cpp(184) : warning C4238:
nonstandard extension used : class rvalue used as lvalue

NotifyMsg is an int.
OpenArgument is a simple class with a constructor:
class OpenArgument: public Argument
{
public:
int Msg;
OpenArgument( int NotifyMsg ): Msg( NotifyMsg ) {}
};

notifyObservers
is a method of OpenArgument that takes an argument pointer:
void notifyObservers(Argument* arg = 0)
{
Observable::notifyObservers( arg );
};

I don't see where the lvalue is in my code though. My only thinking is that
OpenArgument() is a temporary object which I'm taking the address off and
passing it to a method which may somehow be unstandard.

I know that the OpenArgument temp will only have the lifetime of that one
line, which is fine with me. I'm just building it to pass the NotifyMsg to
the method.

Any suggestions? I know that if I created a varaible for OpenArgument
before this and passed the address of that the warning would probably go
away:

OpenArgument TempArg( NotifyMsg );
CloseOnOpenNotifier.notifyObservers( dynamic_cast<Argument*>( &TempArg ) );

but that adds a temp and a line to my code which I really don't need, IMO.
 
A

Alf P. Steinbach

* Jim Langston:
In my code I have this line:
CloseOnOpenNotifier.notifyObservers( dynamic_cast<Argument*>(
&OpenArgument( NotifyMsg ) ) );
which I'm getting a warning on in VC++ .net 2003 when I set the warning
level to 4.
c:\Source\Abyssal\source\Abyssal\CGUIElement.cpp(184) : warning C4238:
nonstandard extension used : class rvalue used as lvalue

'OpenArgument( NotifyMsg )' is an rvalue.

The address operator '&' requires an lvalue.

Also, btw., there is no need for the dynamic cast since Argument is a
base class of OpenArgument.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,284
Latest member
alphabetsalphabets

Latest Threads

Top