I have two classes (ClassA and ClassB) that have two methods (comparison and convergence). These methods work in exactly the same way, but these classes are not polymorphically related (for good reason). I would like to define a function template that both of these classes can explicitly instantiate as a member, but I get errors because the methods use "this", and when I turn them into a template, the compiler throws an error because they are not member functions.
Is this really impossible because of this limitation? Or is there a way to use "this" inside a function template that is not declared as part of the template class. I did some research and found nothing.
Logic.h
template <class T>
T* compare(const T& t) {
}
template <class T>
T* converge(const T& t,bool b) {
}
ClassA.cpp
#include "ClassA.h"
#include "Logic.h"
template ClassA* ClassA::compare(const ClassA& t) const;
template ClassA* ClassA::converge(const ClassA& t,bool b) const;
class B is similar.
!