-1

I just saw a abstract class and it has a few private functions... I am just curious what's the point of private functions for an abstract class?

I assume the children will not have them. Then what's the point there?

WhatABeautifulWorld
  • 3,198
  • 3
  • 22
  • 30

1 Answers1

0

As juanchopanza pointed out, there can be valid reasons for having private virtuals. But an abstract class might have a reason for having non-virtual private data as well.

Perhaps you are under the impression that an abstract class has no data members and only pure virtual functions? This is not the case. A class may have many data members and non-virtual member functions and still be abstract as long as it has at least one pure virtual member function.

class abstract_base {
  public:
  //functionality that derived classes must implement:
  virtual int func1() = 0;

  //functionality that derived classes can't override:
  int get_count() const { return count_; }

  private:
    int count_;
  };

Maybe a silly example, but you get the idea.

zindorsky
  • 1,592
  • 9
  • 9