I have a class BearingX which inherits from a class named Domain. Domain has a private variable "time" and a public method getCurrentTime() which returns the private variable "time".
I need to access this method getCurrentTime() or variable "time" in my class BearingX without creating an object of class Domain. Is it possible, if yes, then how?
Thanks!
If BearingX is derived from Domain, then a BearingX object "IS A" Domain object. (That's why inheritance is often said to represent an "IS A" relationship). You can treat getCurrentTime() as if it's a member of your BearingX class (because it is).
Note - if you've overridden getCurrentTime with your own implementation in BearingX, then to access the version from Domain, you would need to use Domain::getCurrentTime() when calling the function, otherwise you can omit the Domain:: bit
I am sorry for confusion, I confused inheritance with preprocessor directives. My bad!
Okay, so my BearingX doesn't inherit from class Domain. It includes the file like #include <domain.h>.
So now, is there a way to access getCurrentTime() now?
Thank you guys for help.
I finally had to define a method which returned me current domain in the analysis and then got access to getCurrentTime() method: