By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,496 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,496 IT Pros & Developers. It's quick & easy.

return keyword - invalid error message

P: n/a
Raj
Hi,

I was getting an error in my program saying that return keyword must
not be followed by an object expression. I was confused first because I
was using return statement in a valid "if" statement.
e.g. if(expression) return false;

Later, I found that this error was due to a mistake in my method
declaration. I had put void as a return type in my method. When I
changed this to bool, everything works.

I would expect a more meaningfule error message for this type of
errors.

I'm posting this here just to let others know..

Thanks,
Raj

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi

I think you read it wrong, this is the message I get:

Since 'SouthDade.WorkOrder.WorkOrderPagedIterator.GetNex tPage()' returns
void, a return keyword must not be followed by an object expression
This is using VS2003
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Raj" <ra**********@decadesoftware.com> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
Hi,

I was getting an error in my program saying that return keyword must
not be followed by an object expression. I was confused first because I
was using return statement in a valid "if" statement.
e.g. if(expression) return false;

Later, I found that this error was due to a mistake in my method
declaration. I had put void as a return type in my method. When I
changed this to bool, everything works.

I would expect a more meaningfule error message for this type of
errors.

I'm posting this here just to let others know..

Thanks,
Raj

Nov 17 '05 #2

P: n/a
Raj,

Actually, the error message makes perfect sense. Keep in mind that the
return keyword is technically part of every method, regardless of type.
However, for methods of type void it *may* be omitted. Thus, the following
code would be perfectly valid:

public void Foo()
{
// do some stuff

return;
}

However, in case of a method of type void, you must not include an
expression after the return keyword since the method does not return any
data, so the following won't compile:

public void Foo()
{
// do stuff

return 0;
}

Also, if I'm not mistaken, the actual error message should look something
like this:

Since 'Namespace.Class.Method' returns void, a return keyword must not be
followed by an object expression

So the message indicates that the object expression is invalid because the
method type is void.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"Raj" <ra**********@decadesoftware.com> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
Hi,

I was getting an error in my program saying that return keyword must
not be followed by an object expression. I was confused first because I
was using return statement in a valid "if" statement.
e.g. if(expression) return false;

Later, I found that this error was due to a mistake in my method
declaration. I had put void as a return type in my method. When I
changed this to bool, everything works.

I would expect a more meaningfule error message for this type of
errors.

I'm posting this here just to let others know..

Thanks,
Raj

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.