Re: can we return pointer or struct?
- From: "ben" <benhongh@xxxxxxxxxxx>
- Date: Mon, 16 May 2005 23:43:56 +1000
That's correct. In C++, you don't need to prefix contact with struct, just
use contact.
ben
"boki" <bokiteam@xxxxxxxxxxxxxx> wrote in message
news:e8HBJjhWFHA.2648@xxxxxxxxxxxxxxxxxxxxxxx
> Hi , I work on this way, am I right?
>
> Best regards,
> Boki.
> ========================
> struct contact
> {
> int name;
> int telephone_number;
> int email_address;
>
> };
>
> struct contact get_my_contact(void)
> {
> struct contact boki;
> boki.email_address=1;
> boki.telephone_number=3;
> boki.name=2;
> return boki;
>
> }
>
> main()
> {
>
> struct contact boki2;
> boki2 = get_my_contact();
>
> printf("%d",boki2.name);
>
> }
> "ben" <benhongh@xxxxxxxxxxx>
¼¶¼g©ó¶l¥ó·s»D:428898c7$0$10305$afc38c87@xxxxxxxxxxxxxxxxxxxxxxx
> > Reference is a C++ only feature. You may need pointers for
C-compatibility
> >
> > ben
> >
> > "boki" <bokiteam@xxxxxxxxxxxxxx> wrote in message
> > news:uuztHIhWFHA.2692@xxxxxxxxxxxxxxxxxxxxxxx
> >> work on C++, fail on C ? ><!!
> >>
> >>
> >> "ben" <benhongh@xxxxxxxxxxx>
> > ¼¶¼g©ó¶l¥ó·s»D:42887b01$0$8120$afc38c87@xxxxxxxxxxxxxxxxxxxxxxx
> >> > struct contact
> >> > {
> >> > string name;
> >> > int telephone_number;
> >> > string email_address;
> >> > //...
> >> > };
> >> >
> >> > // to return a pointer
> >> > contact* get_my_contact(void);
> >> >
> >> > // to return a struct
> >> > contact get_a_copy_of_someones_contact(const string& who);
> >> >
> >> > ben
> >> >
> >> > "boki" <bokiteam@xxxxxxxxxxxxxx> wrote in message
> >> > news:OATF0JgWFHA.3220@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> Hi All,
> >> >> Can we return pointer or struct? I don't know how to
do...
> >> >>
> >> >> Thank you very much!
> >> >>
> >> >> Best regards,
> >> >> Boki.
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
.
- Follow-Ups:
- Re: can we return pointer or struct?
- From: boki
- Re: can we return pointer or struct?
- References:
- can we return pointer or struct?
- From: boki
- Re: can we return pointer or struct?
- From: ben
- Re: can we return pointer or struct?
- From: boki
- Re: can we return pointer or struct?
- From: ben
- Re: can we return pointer or struct?
- From: boki
- can we return pointer or struct?
- Prev by Date: Re: Internal compiler error problem
- Next by Date: Re: can we return pointer or struct?
- Previous by thread: Re: can we return pointer or struct?
- Next by thread: Re: can we return pointer or struct?
- Index(es):
Relevant Pages
|