473,698 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ 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(voi d);

Is this correct???
Sep 1 '06 #1
3 60833
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
11090
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 automatically now?
3
1597
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 get no error... 2) Length & Length :: operator+ ( void ) const {return * this;} ... I get the error -> 'return' : cannot convert from 'const class Length' to
3
2299
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 System::Drawing::Point __gc* GetData(); then the C# assembly can't see it, presumably because System.Drawing.Point is a struct rather than a class. The managed c++ library compiles OK, it's just the C# assembly doesn't see that method with that return...
127
4875
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
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.