static variables in abstract base classes

Discussion in 'C++' started by pasa_1, Nov 17, 2006.

  1. pasa_1

    pasa_1 Guest

    Are there any reasons one should avoid using static variables in
    abstract base classes?

    Thanks in advance.


    I was considering to do the following:

    #include <iostream>

    using namespace std;

    enum { SZ = 10 };

    class AbstractBaseClass
    {
    protected:
    static int a[SZ];
    public:
    AbstractBaseClass() { }
    virtual void foo() const = 0;
    static void bar(int i) { ++a; }
    };

    int AbstractBaseClass::a[SZ];

    class Derived: public AbstractBaseClass
    {
    public:
    Derived(): AbstractBaseClass() { }
    void foo() const
    {
    int i = 0;
    cout << "Derived::foo(): a[" << i << "]: " << a << endl;
    }
    };
    pasa_1, Nov 17, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DaKoadMunky
    Replies:
    4
    Views:
    549
    Lee Weiner
    Apr 20, 2004
  2. John Gagon
    Replies:
    1
    Views:
    367
    LordAlfredHenry
    May 17, 2006
  3. Ben Finney

    Abstract Base Classes

    Ben Finney, Nov 11, 2005, in forum: Python
    Replies:
    6
    Views:
    404
    Steven D'Aprano
    Nov 14, 2005
  4. pasa_1
    Replies:
    1
    Views:
    322
    mlimber
    Nov 17, 2006
  5. Bart Simpson
    Replies:
    4
    Views:
    308
    James Kanze
    Jun 3, 2007
Loading...

Share This Page