Hello there!
I am currently having some C++ lessons and some of us keep getting the "unresolved external symbol" error. Our teacher never cannot even guess why this is so that is why I turn to you.
Latest example:
The program is going to count votes (yes, no and blank) and in the header file I have the public method "add".
class Elect
{
private:
int yes, no, blank;
public:
void add (int addyes, int addno, int addblank);
[...]
}
I've located the error to the line
void add (int addyes, int addno, int addblank);
If I make it
void add (int addyes, int addno);
it works. So the C++ basically doesn't let me have three (or more) parameters, just two.
Why is that? ._.
And why is that an "unresolved external symbol" error? >_>
Unresolved external error means the compiler found the prototype for a function, but you never gave that function a body (or the linker can't find the body).
This often happens when the parameter list of the prototype does not exactly match the parameter list of the function definition (resulting in them being two separate functions).
To further diagnose, please post how your add() function body is defined. It should look exactly like this:
1 2 3 4
void Elect::add(int addyes,int addno,int addblank)
{
// code here
}
I take it those functions are in a separate cpp file from elect_main.cpp
The problem is that cpp file is not part of your project. As a result, it's not being linked to, which is why the linker is not finding those function bodies.
Assuming this is VS, go in the menu Project | Add Existing Item. Then select whatever cpp file that is. Then rebuild.
EDIT:
Also in the future when you create a new cpp file, do it by going to Project | Add New Item, rather than File | New which is probably what you did last time.
the professor was unable to resolve your question because you forgot to link them to google... please add google to your professor's project list and maybe it can be resolved through them next time...