0

I have a base class named "SensorData", for which different implementations exist. The base class does more, but for the sake of simplicity, let's say I only want the implementations to return a constant, implementation-specific value "maxRange". The obvious way to implement this would be:

Base class:

class SensorData {
  virtual float getMaxRange() = 0;
  virtual ~SensorData();
};

Example implementations would look like this:

class Velo64 : public SensorData {
  inline float getMaxRange() { return 120.0f;}
};

class Velo16 : public SensorData {
  inline float getMaxRange() { return 90.0f;}
};

Additionally, I have a factory that returns a pointer to an implementation.

My question is: Does inlining work here? AFAIK, inlining means the compiler replaces all function calls with the actual function. Since the actual function is not defined at compile time (but instead determined at runtime, depending on which implementation is used?), can the function even be inlined?

I am asking this because the function (and others like it) will be called millions of times per second in a performance-critical application. Alternatively, is there any better way to go? For example, using variables instead of a get-function?

Thomas
  • 4,696
  • 5
  • 36
  • 71
  • ...and I think that the rest of your questions are too broad for this site, as many ways exist to do what you need. – Petr Oct 27 '15 at 15:25
  • thanks for linking to the duplicate, the threads that came up as "related" when I typed this didn't really answer my question. Looks like I'll have to find a different solution. Edit: Am I supposed to delete this question? Or leave it up? Close it? – Thomas Oct 27 '15 at 15:33
  • 1
    I don't know whether there is any consensus of what a "well-behaved" user should do with a duplicate question. I think you might just leave it as is (there are already many of such questions), and maybe it will be auto-deleted soon by some auto-delete criteria. Though deleting it does not seem to hurt anybody too. If you really want to know what is the consensus in this case, you can ask a question on [Meta](http://meta.stackoverflow.com) – Petr Oct 27 '15 at 15:43

0 Answers0