Go to Post I'm pretty sure Andrew Baker and Andy Baker are the same person. Then again, Andy may just be holding out on us. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-26-2010, 04:27 PM
Rafael Vasquez Rafael Vasquez is offline
Registered User
FRC #1245
 
Join Date: Jan 2010
Location: Louisville
Posts: 10
Rafael Vasquez is an unknown quantity at this point
Function returning a struct

I am having some issues with structure handling. The error I'm getting reads:

expected initializer before 'function_name'

Here is some sample code for what I'm trying to do:

struct my_struct{
int a;
int b;
};

.....
//This next line is the line in which the error occurs
my_struct function_name(my_struct my_argument){
.....
}

Does anyone have any ideas on what is causing this and how to fix it?
Reply With Quote
  #2   Spotlight this post!  
Unread 01-26-2010, 04:36 PM
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Function returning a struct

It would help if we saw a better context for the situation. Could you post more, like maybe the whole file, and point out where the error occurs?
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 01-26-2010, 08:30 PM
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: Function returning a struct

Is this in a .c file?
Or .cpp?
__________________
Robots never, ever, ever, ever break -- The Robot Repairman (Backyardigans)
Reply With Quote
  #4   Spotlight this post!  
Unread 01-26-2010, 10:39 PM
Rafael Vasquez Rafael Vasquez is offline
Registered User
FRC #1245
 
Join Date: Jan 2010
Location: Louisville
Posts: 10
Rafael Vasquez is an unknown quantity at this point
Re: Function returning a struct

This is a .cpp file. I don't like adding context to questions like these because I am really after more general answers. In this particular scenario, there is no more context as it is a question that arose while I was teaching some of the younger members of the team about structs. The code above is essentially what I had written in the program to test this out.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-26-2010, 10:55 PM
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Function returning a struct

Is that code inside of a class? I really can't help unless you show more of what's going on and I don't feel like playing 20 Questions. There's nothing wrong with what you posted, but it just shows very basic form.
__________________

Last edited by slavik262 : 01-26-2010 at 11:16 PM.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-27-2010, 12:48 AM
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,182
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Function returning a struct

Quote:
Originally Posted by Rafael Vasquez View Post
I am having some issues with structure handling. The error I'm getting reads:

expected initializer before 'function_name'

Here is some sample code for what I'm trying to do:

struct my_struct{
int a;
int b;
};

.....
//This next line is the line in which the error occurs
my_struct function_name(my_struct my_argument){
.....
}

Does anyone have any ideas on what is causing this and how to fix it?
Code:
 struct my_struct fuctionname(struct my_struct argName)
Or you can typedef the struct.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-27-2010, 06:00 AM
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: Function returning a struct

Quote:
Originally Posted by Rafael Vasquez View Post
This is a .cpp file. I don't like adding context to questions like these because I am really after more general answers.
Ok, but it's clearly being compiled as C code, and that's why more context would have been helpful.

In your original post, you wrote...

Quote:
I am having some issues with structure handling. The error I'm getting reads:

expected initializer before 'function_name'
In this case, the simple answer is, if the code you posted was compiled as C++, you wouldn't get any such error because 'my_struct' becomes implicitly typedef'd.

Which means, IMHO, you are using a C compiler to teach C++ to others.
__________________
Robots never, ever, ever, ever break -- The Robot Repairman (Backyardigans)

Last edited by gvarndell : 01-27-2010 at 10:35 AM. Reason: grammar
Reply With Quote
  #8   Spotlight this post!  
Unread 01-27-2010, 06:53 AM
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Function returning a struct

Quote:
Originally Posted by TomBot View Post
Code:
 struct my_struct fuctionname(struct my_struct argName)
Or you can typedef the struct.
But as gvarndell said, this isn't necessary in a C++ compiler. Something funny is going on here...
__________________
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning... Nate Smith Chit-Chat 3 07-28-2008 10:00 AM
Typedef Struct as function input Mike Programming 13 11-01-2005 06:28 AM
Global Struct Arrays and Interrupts Orborde Programming 5 02-18-2005 10:34 PM
Returning from Nationals archiver 1999 0 06-23-2002 10:39 PM
Returning teams..?.. archiver 2000 1 06-23-2002 10:09 PM


All times are GMT -5. The time now is 09:20 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi