Solved

Passing a data structure by reference causes lnk2019 error

Posted on 2008-10-05
3
324 Views
Last Modified: 2013-12-14
I'm pasting the code below, and the function in question at the top again.  
The function immediately below causes the error.  If I pass by value, it doesn't throw the error at me.  I've also posted the error below.

Thanks!

void fnCalculate(userInput& tempVar1){
}

Error      1      error LNK2019: unresolved external symbol "void __cdecl fnCalculate(struct userInput)" (?fnCalculate@@YAXUuserInput@@@Z) referenced in function "void __cdecl fnGetUserInput(void)" (?fnGetUserInput@@YAXXZ)      main.obj      

#include <iostream>
using namespace std;
struct userInput{
	int units;
	int session;
	int residency;
	char parking;
	char sticker;
	char IDCard;
};
char fnTryAgain(char);
void fnGetUserInput();
void fnCalculate(userInput);
int main()
{
	int varAnswer=1;	
	cout << "Programing running..." <<endl;
	cout << "SMC Fee Calculator."<<endl;		
	while (varAnswer == 1)
	{
	fnGetUserInput();
	varAnswer = fnTryAgain(' ');
	}
	return 0;
}
void fnGetUserInput()
{
	userInput strInput;
	cout << "Enter the number of units enrolled: ";
	cin >> strInput.units;
	cout << "Is this Fall[0], Winter[1], Spring[2] or Summer[3]: ";
	cin >> strInput.session;
	cout << "Are you a state resident[0], non-resident[1] or F1 Visa holder[2]: ";
	cin >> strInput.residency;
	cout << "Do you want a parking decal [y/n]: ";
	cin >> strInput.parking;
	cout << "Do you want an AS sticker [y/n]: ";
	cin >> strInput.sticker;
	cout << "Do you want an ID card [y/n]: ";
	cin >> strInput.IDCard;
	fnCalculate(strInput);
}
 
void fnCalculate(userInput& tempVar1){
 
}
char fnTryAgain(char varReply2)
{
	char varReply1=' ', varReply=' ';
	cout << endl << endl << "Try another scenario?  Enter n for no, any other key for yes: ";
	cin >> varReply1;
	if (varReply1 == 'n'){
		varReply = 0;
	}
	else if (varReply1 == 'N'){
		varReply = 0;
	}
	else
		varReply = 1;
	return varReply;
}

Open in new window

0
Comment
Question by:mike_hale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22644382
both the declaration of the function and the implementation must match the same type of arguments.
So, your declaration at line 13:

     void fnCalculate(userInput);

should be:

     void fnCalculate(&userInput);

to match the implementation at line 44
0
 
LVL 3

Author Comment

by:mike_hale
ID: 22645622
*slaps forehead*

Duh!  That worked.  Thank you Jaime!  
0
 
LVL 3

Author Closing Comment

by:mike_hale
ID: 31503150
Thank you!  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question