i was trying to test the pair class but i keep getting this error. there arent a
ID: 3880816 • Letter: I
Question
i was trying to test the pair class but i keep getting this error.
there arent any error when i just put everything in one cpp file.
ld: symbol(s) not found for architecture x86_64
#include <iostream>
#include "Pair.h"
#include "LinkList.h"
int main()
{
Pair<int,double> q(1,1.2);
q.setFirst(10);
q.setSecond(1.11);
std::cout<< q.getFirst() << std::endl << q.getSecond();
return 0;
}
#ifndef PAIR_H_
#define PAIR_H_
template <class F, class S>
class Pair{
public:
Pair(F,S);
F getFirst();
S getSecond();
void setFirst(F);
void setSecond(S);
private:
F first;
S second;
};
#endif /* PAIR_H_ */
#include "Pair.h"
template <class F, class S>
Pair<F,S>::Pair(F first,S second)
{
this-> first = first;
this-> second = second;
}
template <class F, class S>
F Pair<F,S>::getFirst()
{
return this->first;
}
template <class F, class S>
S Pair<F,S>::getSecond()
{
return this->second;
}
template <class F, class S>
void Pair<F,S>::setFirst(F first)
{
this->first = first;
}
template <class F, class S>
void Pair<F,S>::setSecond(S second)
{
this->second = second;
}
#ifndef LINKLIST_H_
#define LINKLIST_H_
template <class T>
class Node{
public:
void setNode(T node)
{
this->node = node;
};
void setLast()
{
this->node = '';
};
void setNext(Node * next)
{
this->node = next;
};
Node getNode()
{
return this->node;
};
private:
Node* node;
};
template <class T>
class LinkList{
public:
void addFront(T);
void addRear(T);
void insert(Node<T>*, T);
void dele(Node<T>*);
T find(Node<T>*);
LinkList(T);
private:
Node<T> head;
Node<T> next;
};
#endif /* LINKLIST_H_ */
#include "LinkList.h"
template <class T>
LinkList<T>::LinkList()
{
this->head = '/0';
this->next = '/0';
}
template <class T>
void LinkList<T>::addRear(T obj)
{
if(head == '/0')
{
head = new Node<T>;
head->setNode(obj);
next = head;
}
else
{
Node<T> temp;
temp->setNode(obj);
temp->setLast();
next->setNext(temp);
next = next->getNode();
}
}
template <class T>
void LinkList<T>::addFront(T obj)
{
if(head == '/0')
{
head = new Node<T>;
head->setNode(obj);
next = head;
}
else
{
Node<T> temp;
temp->setNode(obj);
temp->setLast(head);
head = temp;
}
}
template <class T>
void LinkList<T>::insert(Node<T>* node, T obj)
{
Node<T> temp = new Node<T>;
temp->setNode(obj);
temp->setNext(node->getNode());
node->setNext(temp);
}
template <class T>
void LinkList<T>::dele(Node<T>* node)
{
Node<T> temp = new Node<T>;
temp = head;
while(temp->getNode() != node && temp->getNode())
{
temp = temp->getNode;
}
if(temp)
{
temp->setNext(node->getNode());
delete node;
}
}
template <class T>
T LinkList<T>::find(Node<T>* head)
{
int size = 0;
Node<T> temp = new Node<T>;
temp = head;
while(temp)
{
size++;
temp = temp->getNode();
}
return size;
}
heres my code
Explanation / Answer
if you are creating own header file and trying to include it, then you must either keep that header file in same directory or during compiling you must include the path of header file.
as u havebt been linking the path of header during compilation so it showed error, but after you kept all in one file directiory linking was not reqiuired and hence it worked without error.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.