0

I am writing a Priority Queue program for a homework assignment and I am receiving the following error, which I do not fully understand. I need a help in order to solve the error, please.

The Error:

Undefined symbols for architecture x86_64:
  "PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getPri()", referenced from:
      _main in main.o
  "PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getStr()", referenced from:
      _main in main.o
  "PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::PriQueue()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is my program code:

#include <iostream>
#include <string>
#include <vector>

template <class T1>
class PriQueue
{
public:

PriQueue();
void enqueue(T1 str, int pri); //Adds to queue
void setStr(T1 newStr);
void setPri(int newPri);
T1 getStr();
T1 getPri();
void dequeue(T1 str, int pri); //Deletes from queue
void peek(T1 str, int pri); //Prints the the first in queue
void size(); //Prints how many in queue

//T1 printQ();

private:

T1 s;
T1 p;

};


template <class T1>
void PriQueue<T1>::enqueue(T1 str, int pri) //Adding an element to the queue
{
this->s = str;
this->p = pri;

}

template <class T1>
void PriQueue<T1>::setStr(T1 newStr)
{
this->s = newStr;

}

template <class T1>
void PriQueue<T1>::setPri(int newPri)
{
this->p = newPri;

}

template <class T1>
void PriQueue<T1>::dequeue(T1 str, int pri) //Removing an element from the front of the queue
{


}

template <class T1>
void PriQueue<T1>::peek(T1 str, int pri) //Returning a value at front of the queue (NOT removing it)
{


}

template <class T1>
void PriQueue<T1>::size() //Returning the number of items in the queue.
{


}

using namespace std;

int main()
{
PriQueue<string> que;

que.setStr("Hello");
que.setPri(4);

cout << que.getStr() << endl;
cout << que.getPri() << endl;



return 0;
}
zneak
  • 134,922
  • 42
  • 253
  • 328
user260739
  • 35
  • 1
  • 1
  • 5

1 Answers1

2

You are not implementing (you are just defining) the getPri() functions, that's why the linker complains.

vsoftco
  • 55,410
  • 12
  • 139
  • 252