I'm trying to wrap my head around some more advanced points of C++ classes as well as possible (or at least with GNU) compiler/built in functions. All of which based on a logger concept for a (large and extensive) work project . Which brings me to this psuedo-code:
class Base {
public:
void increment(){
++m_Val;
}
private:
static int m_Val;
};
class Above : private Base{
public:
void doA(){
//Foo
}
void doB(){
//Bar
}
};
doA()
doB()
increment()
increment()
After stumbling on to this by pure accident; the solution that most closely resembles what I'm looking for is called "Execute-Around pointer" as defined Here. Particularly the section relating to:
Often times it is necessary to execute a functionality before and after every member function call of a class.
Which is represented on the following code snippet taken from aformentioned link.
class VisualizableVector {
public:
class proxy {
public:
proxy (vector<int> *v) : vect (v) {
std::cout << "Before size is: " << vect->size ();
}
vector<int> * operator -> () {
return vect;
}
~proxy () {
std::cout << "After size is: " << vect->size ();
}
private:
vector <int> * vect;
};
VisualizableVector (vector<int> *v) : vect(v) {}
proxy operator -> () {
return proxy (vect);
}
private:
vector <int> * vect;
};
int main()
{
VisualizableVector vecc (new vector<int>);
//...
vecc->push_back (10); // Note use of -> operator instead of . operator
vecc->push_back (20);
}