473,472 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

can functions return a struct?

25 New Member
I am just asking if i can return the values of a struct on a function??
example:
typedef struct sample{
int a;
char b, c;
}SAMPLE_STRUCT;

can it be like this?

//function prototype
SAMPLE_STRUCT copy_struct(void);

Is this correct???
Sep 1 '06 #1
3 60817
f1engineer
5 New Member
It is possible. In header file:

typedef struct sample
{
int a;
char b, c;
}
SAMPLE_STRUCT;
//////
SAMPLE_STRUCT GetSample();

************************************
In source file:

SAMPLE_STRUCT GetSample()
{
SAMPLE_STRUCT sample_struct;

sample_struct.a = 5;
sample_struct.b = 6;
sample_struct.c = 7;

return sample_struct;
}

Also GetSample may the member function of some class, but in this case the structure is must be visible for this class.
Sep 1 '06 #2
rgb
37 New Member
you can also pass your structure as a pointer parameter in your function to make changes in the variables inside the sturcture.
Sep 1 '06 #3
mrusan2000
1 New Member
It is possible. In header file:

typedef struct sample
{
int a;
char b, c;
}
SAMPLE_STRUCT;
//////
SAMPLE_STRUCT GetSample();

************************************
In source file:

SAMPLE_STRUCT GetSample()
{
SAMPLE_STRUCT sample_struct;

sample_struct.a = 5;
sample_struct.b = 6;
sample_struct.c = 7;

return sample_struct;
}

Also GetSample may the member function of some class, but in this case the structure is must be visible for this class.


PLZ. this is must be visible in the same class, if I want see struct variables in the other class.


Thank you in advance.
May 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: lawrence | last post by:
If I want a function to return by reference, I do this? function & myCoolFunction() { $queryObject = new queryObject(); return $queryObject; } I get back a reference to the object...
3
by: Zork | last post by:
Hi, I am a little confused with const functions, for instance (here i am just overloading the unary+ operator) if i define: 1) Length Length :: operator+ ( void ) const {return * this;} ... I...
3
by: BJT | last post by:
Hello, How can I return a struct type e.g. System::Drawing::Point from a managed c++ class to a C# assembly? When I have the declaration of the managed C++ class's member function as...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.