John
John

Reputation: 6648

How to put a function taking an object of a template class as a parameter?

How do I go about writing a function which takes an object of a template class as a parameter? Would the following work? And can it go in the .cpp file instead of a header? (I have only written templated classes before).

template<class T> class LtdArray {
//class definition
}


template<class T> class LtdArray
bool ifBlockProcess(LtdArray &ltdarr, string strToProc) {
//add element to LtdArray
}

Upvotes: 0

Views: 108

Answers (2)

Nate
Nate

Reputation: 12819

When making function templates, you don't need to include the class. Your prototype should look like this:

template<class T>
bool ifBlockProcess(LtdArray<T> &ltdarr, string strToProc);

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 476940

Something like this should do the trick:

template<class T>
bool ifBlockProcess(LtdArray<T> & ltdarr, string strToProc)
{
    //add element to LtdArray
}

Upvotes: 1

Related Questions