Question:
c++ "unresolved external symbol" error LNK2019:?
Sean
2010-02-25 13:44:24 UTC
Im not sure how to fix this, also its my first time using < template class T>

Whatever is wrong cause's 9 issues when run:
1>Generating Code...
1>Compiling...
1>main.cpp
1>Linking...
1>fOp.obj : error LNK2019: unresolved external symbol "public: void __thiscall stack::push(char)" (?push@?$stack@D@@QAEXD@Z) referenced in function "public: void __thiscall fOp::swtchfx(void)" (?swtchfx@fOp@@QAEXXZ)

1>fOp.obj : error LNK2019: unresolved external symbol "public: float __thiscall stack::pop(void)" (?pop@?$stack@M@@QAEMXZ) referenced in function "public: void __thiscall fOp::swtchfx(void)" (?swtchfx@fOp@@QAEXXZ)

1>fOp.obj : error LNK2019: unresolved external symbol "public: char __thiscall stack::peek(void)" (?peek@?$stack@D@@QAEDXZ) referenced in function "public: void __thiscall fOp::swtchfx(void)" (?swtchfx@fOp@@QAEXXZ)

etc....

~~~~~~~here is my stack class..

template
class stack
{
public:
stack(int);
~stack(void);
T pop(void);
void push(T);
bool isEmpty();
T peek();
private:
T *mem;
int max;
int top;
};

~~~~~Here is the class w/function that calls stack

class fOp
{
public:
bool endit;
fOp(void);
~fOp(void);
//gets filename
void getname(void);
//gets all equations from file, stores in linked list (elist)
void nwInfx(void);
//converts infix to postfix
void swtchfx(void); <--------------creates stack: 1 char, 1 float; also is link error
//decides operator importance
int work(char);
//adds values
float compute(float,float,int);
//displays elist
void show();
//control
elist * cursor;
private:
//gets filename
std::string fname;
//used to open file
char *name;
//flag
int txt;
//store infix equation
char infix[30];
//store postfix
char postfx[30];
//stores list of all equations in file
elist * head;
elist * tail;
};


~~~~~~Here is the switchfx() function with the issue......
void fOp::swtchfx(void)
{
//hold equation
char line[30];
//check operator importance
int A;
int B;
//computing
float fa;
float fb;
float fc;
//iterator
int i;
int j;
//max num in stack=16
stack numstk(16);
//max char in stack=15
stack opstk(15);
//reset cursor
cursor=head;
while(cursor!=NULL)
{
//default
memset(line,'\0',30);
i=0;
//set line= to infix
strcpy(line,cursor->getinfx());
for(i=0;line[i]!='\0';i++)
{
if(std::isdigit(line[i]))
numstk.push(line[i]);
else if(line[i]=='(')
{
//substack does inside parenth
stack tmpstk(14);
for(j=i+1;line[j]!=')';j++)
{
if(!opstk.isEmpty())
{
A=work(opstk.peek());
B=work(line[j]);
//compute using a then push b; else push b
if(A>=B||A==3 &&B==4)
{
if(A==5)
fa=fb=numstk.pop();
else
{
fb=numstk.pop();
fa=numstk.pop();
}
fc=compute(fa,fb,A);
numstk.push(fc);
}
}
opstk.push(line[j]);
}
i+=j;
//tmpstk.~stack();
}
else
{
//if empty push;else decide
if(!opstk.isEmpty())
{
A=work(opstk.peek());
B=work(line[i]);
//compute using a then push b; else push b
if(A>=B||A==3 &&B==4)
{
if(A==5)
fa=fb=numstk.pop();
else
{
fb=numstk.pop();
fa=numstk.pop();
}
fc=compute(fa,fb,A);
numstk.push(fc);
}
}
opstk.push(line[i]);
}
}//for(equation)
}//while cursor!=NULLL
}//function


##### So i have no idea how to go about resolving the link error, thanks in advance for trying to help..
Four answers:
MichaelInScarborough
2010-02-25 14:19:19 UTC
it seems that your stack methods peek, push, and pop are not implemented.

The code from the stack class should be in i.e a module called "stack.h"

The methods, static initializations, etc should be in i.e "stack.cpp"

stack.cpp must be added to the project (i.e. make file or project>add existing item> stack.cpp in case you have Visual C++ 2008 (or express edition) otherwise it won't compile and no object file can be linked!
?
2010-02-25 13:48:06 UTC
Make sure you have included the files needed for compiling the program. Unresolved errors usually means the compiler cannot find a definition for a function. As rule of thumb...when I get a lot of errors when compiling, I focus on one problem at a time. Usually fixing just one will clear up a bunch more. Keep at it and enjoy the success you will have once you have figured out the problem.
?
2016-04-12 05:40:50 UTC
Look at the two calcFederalTaxes declarations -- the second just before the implementation. They DON'T AGREE. Look at the parameter lists. The one implemented has ONE parameter, the one declared and called has four integers and a double. It can't find a declaration of the one declared -- which is apparently the one called in your main() only the one with ONE parameter. EDIT: By the way, check your ints. They are all decimals. Ints are not decimals. Ints are WHOLE NUMBERS. Decimals are floats or doubles. You'll have to change it.
Collin
2010-02-25 14:10:32 UTC
Looks like it's having trouble finding the definition of peek, pop, and push. Have you defined those yet somewhere, at least with empty brackets and returns?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...