Click to See Complete Forum and Search --> : Function returning struct
Death on Wheels
11-14-2000, 08:59 AM
How do I write a function that will return a struct?
------------------
Kurt Weber
Shell scripts? Shell scripts? We don't NEED no stinkin' shell scripts!
White, heterosexual, middle-class, and proud!
YaRness
11-14-2000, 09:23 AM
might be easier to just make objects.
have you tried just returning it like any other variable?
*been a long while since i did c++, and no book handy*
------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------
BrianDrozd
11-14-2000, 09:39 AM
struct s
{/* data for struct goes here */};
struct s f ()
{/* Your code goes here */;}
If not you can try:
typedef struct S
{/* data for struct goes here */} s;
s f ()
{/* Your code goes here */;}
[This message has been edited by BrianDrozd (edited 14 November 2000).]
Death on Wheels
11-14-2000, 06:04 PM
Yes, BrianDrozd, I know how to define a struct. However, I'm trying to get a function that returns a struct. I know how to return individual parts of a struct, but I don't know how to return an entire struct.
Your Yarness: This particular struct is the data type for one of the data members of a class.
------------------
Kurt Weber
Shell scripts? Shell scripts? We don't NEED no stinkin' shell scripts!
White, heterosexual, middle-class, and proud!
BrianDrozd
11-14-2000, 06:15 PM
Originally posted by Death on Wheels:
Yes, BrianDrozd, I know how to define a struct. However, I'm trying to get a function that returns a struct. I know how to return individual parts of a struct, but I don't know how to return an entire struct.
I din't mean to imply that you didn't. I am sincerly sorry if that was the message you got. It was not my intention at all. I merely beleive that my examples would not have demonstrated anything if the definitions of the struct had not been included as well.
If what I suggested didn't work, however, try this.
struct s {}
struct s* f ()
{/* your function goes here */;}
Again my apologies if I offended you.