|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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?
|
|
#3
|
||||
|
||||
|
Re: Function returning a struct
Is this in a .c file?
Or .cpp? |
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
Re: Function returning a struct
Quote:
Code:
struct my_struct fuctionname(struct my_struct argName) |
|
#7
|
||||
|
||||
|
Re: Function returning a struct
Quote:
In your original post, you wrote... Quote:
Which means, IMHO, you are using a C compiler to teach C++ to others. ![]() Last edited by gvarndell : 01-27-2010 at 10:35 AM. Reason: grammar |
|
#8
|
||||
|
||||
|
Re: Function returning a struct
But as gvarndell said, this isn't necessary in a C++ compiler. Something funny is going on here...
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |