Using a struct array

Reply

Join Date: Nov 2006
Posts: 2
Reputation: Luwigie is an unknown quantity at this point 
Solved Threads: 0
Luwigie Luwigie is offline Offline
Newbie Poster

Using a struct array

 
0
  #1
Nov 13th, 2006
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.

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,160
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Using a struct array

 
0
  #2
Nov 13th, 2006
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 217
Reputation: Clinton Portis is an unknown quantity at this point 
Solved Threads: 22
Clinton Portis's Avatar
Clinton Portis Clinton Portis is online now Online
Posting Whiz in Training

Re: Using a struct array

 
0
  #3
Nov 13th, 2006
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 2
Reputation: Luwigie is an unknown quantity at this point 
Solved Threads: 0
Luwigie Luwigie is offline Offline
Newbie Poster

Re: Using a struct array

 
0
  #4
Nov 13th, 2006
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:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC