Hello,
I have two classes (ClassA and ClassB) who both have two methods (compare and converge). These methods work exactly the same way, but these classes are not related polymorphically (for good reason). I would like to define a function template that both of these classes can explicitly instantiate as a member but I'm getting errors because the methods use "this" and when I turn them into a template the compiler throws an error because they're not member functions.
Is this impossible because of that limitation? Or is there some way to use "this" inside of a function template that is not declared as part of a template class. I've done some research and found nothing.
Logic.h
template <class T>
T* compare(const T& t) {
//stuff involving this
}
template <class T>
T* converge(const T& t,bool b) {
//other stuff involving this
}
ClassA.cpp
#include "ClassA.h"
#include "Logic.h"
//constructors
template ClassA* ClassA::compare(const ClassA& t) const;
template ClassA* ClassA::converge(const ClassA& t,bool b) const;
//other methods
classB is similar.
Any help is appreciated!