944,120 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8256
  • C++ RSS
Nov 13th, 2006
0

Using a struct array

Expand Post »
Hello there. This is obviously my first post on DaniWeb, as I just found the site in searching for a solution to my issue. I've read over the site rules, as well as the forum rules regarding homework help.

Let me start out by saying I am not looking for an easy solution, or some one to do my work. I'm simply trying to figure out why I can't get this darn thing to compile =)

I'm using Visual C++ 2005 Express Edition, and have pretty much just started coding an end-of-chapter lab assignment.

The issue I'm running into has to do with passing an array of my pre-defined struct into another function. The following is my code.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct menuItemType
  8. {
  9. string menuItem;
  10. double menuPrice;
  11. };
  12.  
  13. void getData(menuItemType menu[]);
  14. void showMenu(menuItemType menu[]);
  15. void printCheck(menuItemType menu[]);
  16.  
  17. int main()
  18. {
  19. menuItemType menu[8];
  20.  
  21. getData(menu);
  22.  
  23. return 0;
  24. }
The errors that I am receiving are:

C++ Syntax (Toggle Plain Text)
  1. 1>Compiling...
  2. 1>Breakfast.cpp
  3. 1>Linking...
  4. 1>Breakfast.obj : error LNK2001: unresolved external symbol "void __cdecl getData(struct menuItemType * const)" (?getData@@YAXQAUmenuItemType@@@Z)
  5. 1>C:\Documents and Settings\Luwigie\My Documents\Visual Studio 2005\Projects\Breakfast\Debug\Breakfast.exe : fatal error LNK1120: 1 unresolved externals
Again, this is in the early construction phase, and I don't seem to be having a compiler error... The error seems to come at the linking stage.

Any help would be greatly appreciated. Also, this looks like an excellent site and source of information =) Glad I stumbled upon it.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luwigie is offline Offline
2 posts
since Nov 2006
Nov 13th, 2006
0

Re: Using a struct array

The link error is telling you that you forgot to code the function getData(). This is not a standard C function -- you have to write it yourself.
Last edited by Ancient Dragon; Nov 13th, 2006 at 11:00 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Nov 13th, 2006
0

Re: Using a struct array

You have done everything right thus far.. the only thing you haven't done, is to provide "function definitions" for your functions.

Below your main( ), go ahead and right up what each function is supposed to do. Here is some pseudo to get ye' started:
C++ Syntax (Toggle Plain Text)
  1. void getData(menuItemType menu[])
  2. {
  3. do stuff...
  4. ....
  5. ....
  6. }
make sure each function prototype has an associated function definition and life will == good.
Last edited by Clinton Portis; Nov 13th, 2006 at 11:01 pm.
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Nov 13th, 2006
0

Re: Using a struct array

Wow. I appreciate the quick response guys.

This dawned on me right after I posted. Doh!

I don't know why throwing a struct definition made me throw everything I've learned thus far out the window :-|

I appreciate the prompt responses guys! Almost wish I could take down this thread out of embarrasment :rolleyes:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luwigie is offline Offline
2 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Blue Screen of Doom!
Next Thread in C++ Forum Timeline: Virtual functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC