#include "stdafx.h"
#include "BlockingStack.h"
int _tmain(int argc, _TCHAR* argv[])
{
BlockingStack<int> stack_wstring(10);
stack_wstring.push(5);
stack_wstring.push(4);
stack_wstring.push(3);
int s;
stack_wstring.get(s);
std::cout << "mystack.top() is now " << s << '\n';
return 0;
}
i don't understand why ,but it dont work...
It produce this errors:
1 2 3 4 5 6
1>Blocking_stack.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall BlockingStack<int>::BlockingStack<int>(int)" (??0?$BlockingStack@H@@QAE@H@Z) non risolto nella funzione _wmain
1>Blocking_stack.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall BlockingStack<int>::~BlockingStack<int>(void)" (??1?$BlockingStack@H@@QAE@XZ) non risolto nella funzione _wmain
1>Blocking_stack.obj : error LNK2019: riferimento al simbolo esterno "public: bool __thiscall BlockingStack<int>::get(int &)" (?get@?$BlockingStack@H@@QAE_NAAH@Z) non risolto nella funzione _wmain
1>Blocking_stack.obj : error LNK2019: riferimento al simbolo esterno "public: void __thiscall BlockingStack<int>::push(int)" (?push@?$BlockingStack@H@@QAEXH@Z) non risolto nella funzione _wmain
1>c:\users\francesco\documents\visual studio 2012\Projects\Blocking_stack\Debug\Blocking_stack.exe : fatal error LNK1120: 4 extern link not solved
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
Because each .cpp file is compiled separately, with no knowledge of other .cpp files.
When compiling the .cpp file with _tmain in it, the compiler doesn't see the definitions of BlockingStack<T> if they are not in the include file, so it compiles calls to those member functions, assuming they are defined somewhere else.
When compiling BlockingStack.cpp, the compiler doesn't see anything using BlockingStack<int> or any other BlockingStack<T>, so nothing is compiled.
When linking the results together, the linker finds calls to BlockingStack<int>::BlockingStack<int>(int) and others, which lead nowhere, and reports that.