salve, ho qui un programma che nn ha errori di compilazione ma vc++ mi segnala errori nel link
---------------------------------------------------------------------------------------
//stack1.h
#ifndef STACK1_H
#define STACK1_H
template <typename T> class Stack{
public:
Stack(int=10);//costruttore
~Stack();//ditruttore alt+126
bool Push(T);
bool Pop(T &);
bool isEmpty();
bool isFull();
void getTOS(int &);
private:
int size;
T *ptr;
int top;
};
#endif
---------------------------------------------------------------------------------------
//stack.cpp
#include "stack1.h"
#include <iostream>
using namespace std;
//costruttore ello stack
template <typename T> Stack <T>::Stack(int num):size(num > 0 ? num : 10),ptr(new T[size]),top(-1){}
//inserimento di un elemento in testa
template <typename T> bool Stack <T>::Push(T obj){
if(top<size-1){
ptr[top]=obj;
++top;
return 1;
}
cout<<"Stack pieno.\nNon è possibile inserire nuovi elementi\n";
return 0;
}
//toglie un elemento dalla testa
template <typename T> bool Stack <T>::Pop(T &obj){
if(top>-1){
obj=ptr[top];
--top;
return 1;
}
cout<<"Stack vuoto.\nImpossibile togliere elementi\n";
return 0;
}
template <typename T> bool Stack <T>::isEmpty(){return(top==-1 ? 1:0);}
template <typename T> bool Stack <T>::isFull(){return(top==(size-1) ? 1:0)};
template <typename T> Stack <T>::~Stack(){delete [] ptr;}
template <typename T> void Stack <T>::getTOS(int &TOS){TOS=top;}
---------------------------------------------------------------------------------------
//main.cpp
#include "stack1.h"
#include <iostream>
using namespace std;
int main(){
int siz;
int obj;
int TOS;
cout<<"Immetti la dimensione dello stack...\n";
cin>>siz;
Stack <int> intStack(siz);
cout<<"push 2 interi nello stack...3 2..\n";
intStack.Push(3);
intStack.Push(2);
intStack.getTOS(TOS);
cout<<"TOS: "<<TOS<<"\n";
cout<<"pop 1 elemento..\n";
intStack.Pop(obj);
cout<<"L'elemento poppato è: "<<obj<<"\n";
return 0;
}
---------------------------------------------------------------------------------------
Quando linko ho:
Compiling...
main.cpp
stack.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Stack<int>::~Stack<int>(void)" (??1?$Stack@H@@QAE@XZ)
main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack<int>::Pop(int &)" (?Pop@?$Stack@H@@QAE_NAAH@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Stack<int>::getTOS(int &)" (?getTOS@?$Stack@H@@QAEXAAH@Z)
main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Stack<int>::Push(int)" (?Push@?$Stack@H@@QAE_NH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall Stack<int>::Stack<int>(int)" (??0?$Stack@H@@QAE@H@Z)
Debug/stack.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
stack.exe - 6 error(s), 0 warning(s)
---------------------------------------------------------------------------------------
Qualcuno mi puo aiutare?
Grazie