Warning - declares a non-template function

Hello experts i get strange warning message/

cont.h:8: warning: friend declaration `bool operator==(const Container<T>&, const Container<T>&)' declares a non-template function
cont.h:8: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning

I have a template class
 
template <class T>


and made
 
friend bool operator==(const Container<T> &rhs,const Container<T> &lhs);

which in code is
1
2
3
4
5
6
7
8
//~ //---test for equal elements values in the two containers rhs and lhs
template <class T>
bool operator==(const Conatiner<T> &rhs,const Container<T> &lhs){
	if (rhs.sizeC == lhs.sizeC) {
		return true;
	}
	return false;
}

what am i doing wrong?
Last edited on
closed account (1yR4jE8b)
You have the friend statement inside of your class, and the operator is a global function...am I correct?

If this is the case, the friend declaration must also be a template but because you're inside of a template class you can't reuse the T parameter or you will shadow the original parameter:
1
2
template <class F>
friend bool operator==(const Container<F> &rhs,const Container<F> &lhs);

Last edited on
Topic archived. No new replies allowed.