corey taylor wrote:
Morten,
Well, if those are all the files you have, then the issue is simply that you never implemented the Stack class methods that gcc throws out as "undefined references."
Only the method definitions are there which allow a compilation, however the linker will error trying to connect the symbols to actual code.
corey
Thanks,
actually something was missing. not only a small typo.
I searched and found it here.
http://www.josuttis.com/tmplbook/basics/stack5test.cpp.html
the missing piece is
http://www.josuttis.com/tmplbook/basics/stack5.hpp.html
#ifndef STACK_HPP #define STACK_HPP
#include <deque> #include <stdexcept>
#include "stack5decl.hpp <http://www.josuttis.com/tmplbook/basics/stack5decl.hpp.html>"
#include "stack5assign.hpp <http://www.josuttis.com/tmplbook/basics/stack5assign.hpp.html>"
template <typename T> void Stack<T>::push (T const& elem) { elems.push_back(elem); /// append copy of passed elem/ }
template<typename T> void Stack<T>::pop () { if (elems.empty()) { throw std::out_of_range("Stack<>::pop(): empty stack"); } elems.pop_back(); /// remove last element/ }
template <typename T> T Stack<T>::top () const { if (elems.empty()) { throw std::out_of_range("Stack<>::top(): empty stack"); } return elems.back(); /// return copy of last element/ }
#endif /// STACK_HPP
/
it compiles and runs fine
bash-2.05$ g++ -ansi -pedantic -Wall -o stack5test.out stack5test.cpp -L /opt/sfw/gcc-3/lib -R /opt/sfw/gcc-3/lib -lstdc++
bash-2.05$ ./stack5test.out
7
42
Exception: Stack<>::top(): empty stack
No complains from gcc,
g++ -v
Reading specs from /opt/sfw/gcc-3/lib/gcc-lib/i386-pc-solaris2.9/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --prefix=/opt/sfw/gcc-3 --with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as --without-gnu-ld --without-gnu-as --enable-shared
Thread model: posix
gcc version 3.3.2
Best regards
Morten
/ /