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. Advertisements

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:
    714
    Lee Weiner
    Apr 20, 2004
  2. John Gagon
    Replies:
    1
    Views:
    496
    LordAlfredHenry
    May 17, 2006
  3. Ben Finney

    Abstract Base Classes

    Ben Finney, Nov 11, 2005, in forum: Python
    Replies:
    6
    Views:
    595
    Steven D'Aprano
    Nov 14, 2005
  4. pasa_1
    Replies:
    1
    Views:
    399
    mlimber
    Nov 17, 2006
  5. Bart Simpson
    Replies:
    4
    Views:
    418
    James Kanze
    Jun 3, 2007
  6. Daniel Nogradi

    Voluntary Abstract Base Classes

    Daniel Nogradi, Jun 29, 2007, in forum: Python
    Replies:
    1
    Views:
    333
    James Stroud
    Jun 29, 2007
  7. Dan Smithers

    templates and abstract base classes

    Dan Smithers, Jun 19, 2008, in forum: C++
    Replies:
    4
    Views:
    504
    Dan Smithers
    Jun 20, 2008
  8. Vinesh S
    Replies:
    4
    Views:
    578
    Vinesh S
    Aug 22, 2011
Loading...