I have multiple classes that are quite different in their behavior, but at the same time, share common functions that have to access the member variables.
So what I want to do, is to create a templated member function to avoid extra copy-paste code duplication.
The final result should be like:
ClassA::CallFoo()
ClassB::CallFoo()
ClassC::CallFoo()
where CallFoo() is defined in a shared file like [weirdo hypothetical syntax]
<template this* T>::CallFoo(){T->memberX->DoStuff();}
Is something like that possible with C++? I cant seem to find anything concerning code reuse and multiple classes.
EDIT: I have multiple classes, ClassA, ClassB, ClassC, ... ClassX, all of which have a member variable memberX. In order to use that member variable inside the member functions of the classes, I have to do some setup and preprocessing on that variable, which is equal for all of the classes. So ClassA can have a method DoCoolStuff1() which has to call [shared code] to get the updated shared variable, ClassB can have a method DoBoringStuff1() which also calls [shared code].
Unfortunately, memberX is not in my source code, but in library headers ClassA : public LibClass, so I cannot override it there.