Mình đang tạo ra stack với header và class 2 file riêng biệt. Nhưng lúc mình chạy thì lại báo lỗi thế này . Mình đã thử google nhưng không cách nào được. Các bạn xem giúp mình
Compiling: g++ Instructor_prog2_3.cpp Tokenizer.cpp Stack.cpp -o proginstructor_2_3
/tmp/ccDEp56i.o: In function `main':
Instructor_prog2_3.cpp:(.text+0x68): undefined reference to `Stack::Stack()'
Instructor_prog2_3.cpp:(.text+0x89): undefined reference to `Stack::Push(int)'
Instructor_prog2_3.cpp:(.text+0x9b): undefined reference to `Stack::Print()'
Instructor_prog2_3.cpp:(.text+0xdc): undefined reference to `Stack::Pop()'
Instructor_prog2_3.cpp:(.text+0x116): undefined reference to `Stack::Print()'
collect2: error: ld returned 1 exit status
Compile Fail
#ifndef Stack_h
#define Stack_h
#include <iostream>
#include <vector>
using namespace std;
template <class T>
class Stack
{
private:
vector<T> elements;
public:
Stack<T>();
void Push(T value);
T Pop();
void Print();
};
#endif
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdexcept>
#include "Stack.hpp"
using namespace std;
template <class T>
void Stack<T>::Push(T value){
this->elements.push_back(value);
}
template <class T>
T Stack<T>::Pop(){
if (this->elements.empty()){
throw out_of_range("Stack Empty!");
}
return this->elements.pop_back();
}
template <class T>
void Stack<T>::Print(){
if (this->elements.empty()){
throw out_of_range("Stack Empty!");
}else{
cout << "[ " ;
for (int i=0; i < this->elements.size(); i++){
cout << this->elements[i] ;
}
cout << " ]" ;
}
}


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?