1

I have an abstract class AbstractBufferQueue and BufferQueueAverage is the class which is being used in the code always.

class AbstractBufferQueue 
{
    virtual void addSample(int s) = 0;
    virtual void removeSample(int s) = 0;

    void enqueue(int val) 
    {
        ...
        addSample(val);
    }
}

class BufferQueueAverage : public AbstractBufferQueue
{
    int n;
    double mean;

    void addSample(int s) { ++n; mean += (s - mean) / n; }
    void removeSample(int s) { ... }
    double getAverage() const { return mean; }
}

This question is from the compilers optimizations perspective.I want to know if we can make the virtual functions of the class AbstractBufferQueueAverage as inline.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
v78
  • 2,803
  • 21
  • 44
  • 1
    The accepted answer to http://stackoverflow.com/questions/733737/are-inline-virtual-functions-really-a-non-sense seems to answer this well. – Bathsheba Sep 13 '16 at 10:52
  • 1
    From the compiler writer's perspective, sure you can. Your compiler just wouldn't be a conforming implementation of the C++ language. – sepp2k Sep 13 '16 at 13:56

0 Answers0