Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I return a NULL reference?

8 views
Skip to first unread message

Jeremy Chaney

unread,
Feb 16, 2007, 8:13:53 PM2/16/07
to
Forgive me if this is a dumb question. It seems like such a simple thing
that I shouldn't have to ask, but alas, I can't seem to figure it out.

I'm porting some C++ code to MC++ and I have a function that formerly
returned either a valid pointer, or NULL. In MC++, how do I return NULL?
If I try "return NULL;" I get a "cannot convert from 'int' to ..." error.

Thanks,
--Jeremy

David Lowndes

unread,
Feb 17, 2007, 4:26:20 AM2/17/07
to
>I'm porting some C++ code to MC++ and I have a function that formerly
>returned either a valid pointer, or NULL. In MC++, how do I return NULL?
>If I try "return NULL;" I get a "cannot convert from 'int' to ..." error.

Jeremy,

Is nullptr perhaps what you're looking for?

Dave

Bruno van Dooren [MVP VC++]

unread,
Feb 17, 2007, 6:12:06 AM2/17/07
to
> >I'm porting some C++ code to MC++ and I have a function that formerly
>>returned either a valid pointer, or NULL. In MC++, how do I return NULL?
>>If I try "return NULL;" I get a "cannot convert from 'int' to ..." error.
>
> Is nullptr perhaps what you're looking for?

nullptr is a VC2005 thing that doesn't exist in VC2003.
If the op uses C++/CLI, nullptr will work. With MC++ it won't.

With VC2003 you can use NULL.
e.g. this compiles without problem:
System::String *s = NULL;

OP: What is the function prototype?

--

Kind regards,
Bruno van Dooren
bruno_nos_pa...@hotmail.com
Remove only "_nos_pam"


Jeremy Chaney

unread,
Feb 17, 2007, 10:22:09 PM2/17/07
to
nullptr did it. Thanks. You would think that that would have been easy
to find. I guess I just looked in all of the wrong places. Thanks,
--Jeremy

Bruno van Dooren [MVP VC++]

unread,
Feb 18, 2007, 5:47:54 AM2/18/07
to
> nullptr did it. Thanks. You would think that that would have been easy
> to find. I guess I just looked in all of the wrong places. Thanks,
> --Jeremy

Hi,
just for future reference: if you use .NET with Visual C++ 2005, you are
using C++/CLI.
with VC2003 it is called 'Managed Extensions for C++', 'Managed C++' or
simply 'MC++'
these are completely incompatible, so if you are searching for information,
be sure to use the correct name or you'll find lots of information that are
of no use to you anymore.

Jeremy Chaney

unread,
Feb 21, 2007, 12:26:46 PM2/21/07
to

Good to know. I had been searching with "MC++" and then translating old
syntax to new syntax. I'll use C++/CLI instead.

Thanks,
--Jeremy

0 new messages