I would like guidence about how to appoach my generic function pointer library
Hi all,
I recently read about the fundementals of pointers and how I can use them to point to objects and class methods. The steps that I have recently taken to point to class methods are, for example:
declare Class2, include Class1.h in Class2.h
- declare a pointer to an object of Class1 as private in Class2.
- instantiate an object of Class2
- call a Class2 method to init the private pointer to a specific Class1 instance
- access the referenced Class1 variable from inside my Class2 methods and/or call Class1 methods.
Here is a segment of code that is located in my main.cpp:
Code:
MODSERIAL pc(USBTX, USBRX);
msExtensions msExt = msExtensions(pc);
cfExtensions cfExt = cfExtensions(msExt);
exeCallback exeCmd;
phSensor phS = phSensor(cfExt, msExt);
While that code seems to work well; however, is there a better way to approach this? Is it possible to only point to a few methods of a specific object instead of passing the whole object to the class that requires access to the class's methods? Perhaps I am missing the point and I am required to pass the whole object to gain access to those methods even though I only require access to 2 to 3 methods?