| | |
error LNK2001: unresolved external symbol
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 3
Reputation:
Solved Threads: 0
I am trying to write a program that computes the area of a right triangle. It has to use a function to compute the area. This is actually a part of a bigger program, but when I couldn't get it to work I isolated this section. I tried looking on google for help, but nothing I found seemed to help. I get no errors when I compile, but when I try to execute I get the following error:
Below is my code:
Any pointers/help would be appreciated.
TIA
Heather
•
•
•
•
Linking...
area.obj : error LNK2001: unresolved external symbol "double __cdecl findarea(double,double)" (?findarea@@YANNN@Z)
Debug/area.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
area.exe - 2 error(s), 0 warning(s)
C++ Syntax (Toggle Plain Text)
//Program to compute the area of a right triangle #include <iostream> #include <iomanip> #include <fstream> //Declare std using std::cout; using std::cin; using std::endl; using std::ios; using std::cerr; using std::ofstream; //Function Prototype double findarea (double,double); //Start the program int main () { //Declare the variables double a; //side a double b; //side b double d; //area //Open the file for output ofstream datafile ("program.txt", ios::out); //Error routine if file can not be created if (!datafile) { cerr << "File could not be opened" << endl; exit (1); } //Initialize a a=1; //Describe program to user cout << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program."; datafile << "This program will compute the area of a right triangle.\n\nSet side a or b to 0 or less to end the program."; //Begin the WHILE loop to set sentinal value to loop the program while (a>0){ //Get a cout << "\n\nEnter the length of side a: " << endl; cin >> a; datafile << "\n\nSide a is: " << a << endl; //Use an IF to dictate the behavior of the program if a>0 and get b if (a>0){ cout << "\nEnter the length of side b: " << endl; cin >> b; datafile <<"Side b is: " << b << endl; //Allow for b<=0 if (b<=0){ cout << "\n\nYou have ended the program." << endl; datafile << "You have ended the program." << endl; break; } d=findarea(a,b); cout << "\nThe area is: " << d << endl; datafile << "The area is: " << d << endl; //End IF } //Start ELSE to allow output that tells the user they have ended the program else { cout << "\n\nYou have ended the program." << endl; datafile << "You have ended the program." << endl; //End ELSE } //End WHILE } //End program return 0; } double findarea (double q,double r,double s) { s=(q*r)/2; return s; }
Any pointers/help would be appreciated.
TIA
Heather
Compare and contrast:
>double findarea (double,double);
>d=findarea(a,b);
>double findarea (double q,double r,double s) {
Be sure to take careful note that the declaration takes two arguments and the definition takes three. C++ treats these as two unique functions that are overloaded to have the same name, therefore the linker is complaining about your not defining the findarea that takes two arguments.
>double findarea (double,double);
>d=findarea(a,b);
>double findarea (double q,double r,double s) {
Be sure to take careful note that the declaration takes two arguments and the definition takes three. C++ treats these as two unique functions that are overloaded to have the same name, therefore the linker is complaining about your not defining the findarea that takes two arguments.
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 3
Reputation:
Solved Threads: 0
Part of my confusion came from the fact I had done a different program set up the same way... prototyped-(double, double) invoked-(a,b) then defined-(double x, double y, double z) for finding the hypotenuse of a right triangle...and it compiled and linked and worked fine for whatever fluke reason. Then we had to make it also do the area and I set it up like I had the hypotenuse function...and the hypotenuse still worked but then the area part errored out. So I pulled the area part of it and made a program just for that....it still errored on the linking...I couldn't figure out why, so that is why I came on here yelling for help. My teacher even said "I can tell you why the area function did NOT work, but I can't explain why the hypotenuse one DID work." Just a fluke thing that for some reason I got away with. So now I know...lol
![]() |
Similar Threads
- error LNK2001: unresolved external symbol - only happens with STATIC variable (C++)
- error LNK2001: unresolved external... (C)
- unresolved external symbol error (C++)
- error LNK2001: unresolved external symbol (C++)
- Need help with "error LNK2001 unresolved external symbol" (C++)
- error LNK2001: unresolved external symbol (C++)
- error LNK2001: unresolved external symbol (C++)
- error LNK2001: unresolved external symbol (C++)
Other Threads in the C++ Forum
- Previous Thread: Error message when trying to compute using sqrt
- Next Thread: fairly basic c++ code that demonstrates many aspects
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







Function overloading problems tend to be incredibly subtle and difficult to find, even for experienced C++ programmers.