The google references were a bit varied and ambiguos and my textbook ironically doesn't cover templates ._.

if I were to make

template <typename typ> 
	class stk {
			public:
				stk();
				~stk();
			private:
				struct STK {
					typ dat;
					STK *lnk;
				}; *chn;
				int ctr;			
	};

do I have to do anything special for my implementation file or would I go about declaring each function like normal? Like

stk<typ>::stk(){

as opposed to
stk::stk(){

Recommended Answers

All 4 Replies

Try this one:

template<typename typ>
stk<typ>::stk(){

}

So I have to redeclare the template in the implementation?

Yes, and if your compiler does not support the keyword export,
then it has to be in the same file. (note not tested)
For example :

//pair.h
#ifndef PAIR_H_
#define PAIR_H
template<typename Type, template Type2>
class Pair
{
  private: 
   Type first;
   Type second;
 public:
   Pair() : first(0), second(0) { }
   Pair(Type a, Type2 b);
   
   void prntAll();
}

template<typename Type, typename Type2)
Pair<Type, Type2> :: Pair(Type a Type2 b) : first(a), second(b) { }

template<typename Type, typename Type2)
Pair<Type, Type2> :: prntAll() { std::cout<<first<<" , "<<second<<"\n";
}

#endif
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.