Unresolved issue

I get the error
1
2
1>Rpn.obj : error LNK2019: unresolved external symbol "public: void __thiscall Queue::add(float)" (?add@Queue@@QAEXM@Z) referenced in function "private: void __thiscall RPNEval::ProcessOperator(char)" (?ProcessOperator@RPNEval@@AAEXD@Z)
1>F:\School\Platteville\CS2640\Prog1\Debug\RpnTest.exe : fatal error LNK1120: 1 unresolved externals


I don't understand how to fix this besides the fact that the linker cant find the file to compile the program correctly.

my code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "Rpn.h"

void RPNEval::ProcessOperator( char operation)
{
	float numberOne;
	float numberTwo;
	float numberThree;
	if( stack.isEmpty() )
		cout << "Empty" << endl;//invalidExpression( );
	else
		numberOne = stack.pop( );
      
	if( !stack.isEmpty( ) )
	{
		numberTwo = stack.pop();
		if( operation == '*' )
			numberThree = numberTwo * numberOne;
		else if( operation == '+' )
			numberThree = numberTwo + numberOne;
		else if( operation == '-' )
			numberThree = numberTwo - numberOne;
		else if( operation == '/' )
			numberThree = numberTwo / numberOne;
         
		queue.add(numberThree);
		stack.push(numberThree);
	}
	else
	{
		//invalidExpression( );
	}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef __RPNEVAL_H
#define __RPNEVAL_H

#include "stack.h"
#include "queue.h"

typedef float OperandType;

class RPNEval
{
   public:
       ......

   private:
      bool valid;
      OperandType answer;
      Stack stack;
      Queue queue;

	  void ProcessOperand();
	  void ProcessOperator(char ch);
	  void PrintResults();
};

#endif 
Last edited on
Hi,

Errors like this often mean you haven't defined Queue::add(float), what does "queue.h" look like.

Some other breaking news, you didn't check for divide by zero :+)

Edit: You also need an else statement on line 24 of your first code snippet. Need to catch invalid operations somewhere.
Last edited on
I was saving divide by 0 for later hahah, but my queue.h is below, but the way my class is set up, he wants if the method is longer than 1 line it must be defined in the cpp so I'll inlcude the cpp also

queue. h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifdef Testing_Queue
#include <iostream>

using namespace std;

#endif

class Queue
{
public:

   /**
   Initializes a queue of a specific size and sets
   the front, rear and count all to 0.
   @param size 
   */
   
   Queue (){front = rear = count = 0;}

   /**
   Allows a object to be added to the queue in this case
   a fraction.
   @param x fraction to be added
   */
   
   void add ( QInfoType x );

   /**
   Allows for a object to be removed from the queue in the
   rear of the queue.
   @return the fraction object to be removed
   */
   
   QInfoType remove( );
   
   /**
   Test to see if the queue is empty which if the queue
   is empty, count would equal 0. If the queue is empty,
   it returns true, if count is not 0, it returns false.
   @return true or false if queue is empty or not
   */ 
   
   bool isEmpty( ){return count == 0;}
   
   /**
   Clears the whole queue when prompted.
   */
   
   void clear( );

   enum {MAXQ = 80};

private:

	QInfoType elements[MAXQ];
	int front, rear, count;
};

#endif 


queue.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Queue.h"

void Queue::add ( QInfoType x )
{
	elements[ rear ] = x;
	rear = ( rear + 1 ) % MAXQ;
	++count;
}

QInfoType Queue::remove()
{
	QInfoType x = elements[ front ];
	front = ( front + 1 ) % MAXQ;
	--count;
	return x;
}

void Queue::clear( )
{
	for( int i = 0; i < MAXQ; i++ )
		elements[ i ] = 0;
	count = 0;
}

void main()
{
	Queue queue;
	queue.add( 3.4 );
	cout << "3.4 was added to the queue" << endl;
	queue.add( 1.2 );
	cout << "1.2 was added to the queue" << endl;
	queue.add( 5.7 );
	cout << "5.7 was added to the queue" << endl;
	queue.add( 9.01 );
	cout << "9.01 was added to the queue" << endl;
      
	QInfoType temp1 = queue.remove( );
	QInfoType temp2 = queue.remove( );
      
	cout << temp1 << " was removed from the queue" << endl;
	cout << temp2 << " was removed from the queue" << endl;
      
	queue.clear( );
      
	if( queue.isEmpty( ) )
		cout << "The queue was cleared" << endl;
	else
		cout << "The queue was not cleared" << endl;
};
Last edited on
void Queue::add ( QInfoType x )

You have this defined, but not void Queue::add ( float x )

Also, it's int main not void main , that is mandated by the C++ standard.
Last edited on
I get the same error if I cast QInfoType(x) though
I get the same error if I cast QInfoType(x) though


Don't resort to casting, define a function with the proper types :+)

IMO, you don't need void Queue::add ( QInfoType x ), because QInfoType elements[MAXQ]; is a member variable.

Add is misleading, it implies addition. Consider Append or Push

Also, prefer to use double, the precision of a float is easily exceeded.

Don't have using namespace std; it will cause problems for you one day.
QInfoType is not a type. Maybe you need templates?
It's for a class and using namespace std; float are apart of the programming ground rules for now. We submit out program online with a computer generated test code so any answer even to the smallest decimal will cause an error so converting to double from float may be a problem just for this project.

Also with the add method, I can have it named anything I want but we are required to have that particular method
Also we havent learned templates yet so we are not allowed to use them
Ok. make elements[MAXQ] of type float then :+) And make Queue::add accept a float

Good Luck !!
Topic archived. No new replies allowed.