![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Difficulty Passing Structure Data Elements Between FunctionsHi,
I am having some difficulty passing structure data between different functions in a program I'm working on for school. I am receiving several compile errors. Code and errors appear below, in that order. Please forgive if I've copied too much code in, as I'm not sure exactly where my problem lies. CPP / C++ / C Code:
The errors I received are: for driver.cpp Compiling... Driver.cpp C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Driver.cpp(39) : error C2660: 'WriteEnvelope' : function does not take 1 parameters c:\documents and settings\jerry brinegar\desktop\cp278 - visual c++\cp 287b c++\brinegarp1\envelope.cpp(43) : error C2065: 'env' : undeclared identifier c:\documents and settings\jerry brinegar\desktop\cp278 - visual c++\cp 287b c++\brinegarp1\envelope.cpp(44) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition Error executing cl.exe. Driver.obj - 3 error(s), 0 warning(s) for envelope.cpp Compiling... Envelope.cpp C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : error C2146: syntax error : missing ';' before identifier 'AskUserForEnvelope' C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : error C2501: 'Envelope' : missing storage-class or type specifiers C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : fatal error C1004: unexpected end of file found Error executing cl.exe. Envelope.obj - 3 error(s), 0 warning(s) I'm fairly certain this has to do with what's passed into the functions and the return types that passes it back, but am unsure where and am getting a little confused on what's really passing back. Coneptually, AskUserForAddress should be passing back "a" to AskUserForEnvelope 2 times, as e.sender and e.receiver, then AskUserForEnvelope should pass back "e" (sender/receiver) to the main method (env) which is in turn passed to WriteEnvelope. Or am I totally off? Thanks. |
|||
|
#2
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsQuote:
Quote:
So let us take a look at that. CPP / C++ / C Code:
Now let us find the function "WriteEnvelope". CPP / C++ / C Code:
Now we can take a look at the prototype. CPP / C++ / C Code:
Now see what you you can do with the rest of the errors. Post back with any questions and include any updated code and any errors you receive. Good luck. |
|
#3
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsCPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsI apologize but I'm not following what you mean.
The prototype should be something like: CPP / C++ / C Code:
and CPP / C++ / C Code:
Parameters need types, also. You mean it should be CPP / C++ / C Code:
??? |
|
#5
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsWell, from this line in WriteEnvelope (and other lines)
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
By the way, perhaps WriteEnvelope should return void because it is defined as returning an Envelope, but if you look in the function definition there is no return statement. |
|
#6
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsYes, I agree about not sending data back from WriteEnvelope, there isn't any need, So I've changed that:
CPP / C++ / C Code:
But I still have my compile errors in Envelope.cpp. ompiling... Envelope.cpp C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : error C2146: syntax error : missing ';' before identifier 'AskUserForEnvelope' C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : error C2501: 'Envelope' : missing storage-class or type specifiers C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(5) : fatal error C1004: unexpected end of file found Error executing cl.exe. BrinegarP1.exe - 3 error(s), 0 warning(s) Thank you! |
|
#7
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsWell you are giving it a data type of Envelope, but the compiler doesn't know what that data type is. You need to include Envelope.h in Envelope.cpp
Then wehn the compiler tries compiling Envelope.cpp it will know what type Envelope is. |
|
#8
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsThere are 2 .cpp files: driver.cpp and envelope.cpp. In driver there is an include for envelope.h:
CPP / C++ / C Code:
If I were to add the #include statement into envelope.cpp I would get redefinition errors because it already exists in driver.cpp: Compiling... Driver.cpp c:\documents and settings\jerry brinegar\desktop\cp278 - visual c++\cp 287b c++\brinegarp1\envelope.h(6) : error C2011: 'Address' : 'struct' type redefinition c:\documents and settings\jerry brinegar\desktop\cp278 - visual c++\cp 287b c++\brinegarp1\envelope.h(11) : error C2011: 'Envelope' : 'struct' type redefinition Error executing cl.exe. Driver.obj - 2 error(s), 0 warning(s) So, I'm back where I started with the errors compiling envelope.cpp: Compiling... Envelope.cpp C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(6) : error C2146: syntax error : missing ';' before identifier 'AskUserForEnvelope' C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(6) : error C2501: 'Envelope' : missing storage-class or type specifiers C:\Documents and Settings\Jerry Brinegar\Desktop\CP278 - Visual C++\CP 287B C++\BrinegarP1\Envelope.cpp(6) : fatal error C1004: unexpected end of file found Error executing cl.exe. BrinegarP1.exe - 3 error(s), 0 warning(s) |
|
#9
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsIt is the way you are including it, I didn't notice that or I would have told you before. You are including the envelope.cpp wrong.
If I include it like a header file here are the errors I get Quote:
But if I don't #include "Envelope.cpp" And instead include the file in my project in my compiler then here is what happens. Quote:
It successfully builds the project, the reason for this is because it compiles each .cpp file seperately, so it doesn't see the include files from the other .cpp files. I included this in both driver.cpp and Envelope.cpp Code:
You will notice certain files don't have the .h extension and I also have "using namespace std;" that isn't to do with the problem, that is just because that is modern C++. Your code seems to be using older C++, but my compiler requires newer C++. The actual problem as I said was that firstly you are including the .cpp file wrong, it needs to be added to your project. If you are compiling from the command line I am not sure the switch you need to use in order to let the compiler know you are using multiple .cpp files. This would come down to your specific compiler so you would need to search the docs. Secondly, once you have added the cpp file correctly just include envelope.h and it will (should) compile fine as I showed |
|
#10
|
|||
|
|||
Re: Difficulty Passing Structure Data Elements Between FunctionsI think I got it....Thanks!!!!
|
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| Strange C++ code memory leakage problem | gaoanyu | C++ Forum | 7 | 04-Nov-2005 09:09 |
| passing tables as arguments to functions. | kobi_hikri | C Programming Language | 8 | 27-Jul-2005 08:29 |
| [GIM] gim.h | dsmith | C Programming Language | 0 | 18-Jan-2005 09:48 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The