static variables in abstract base classes

P

pasa_1

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;
}
};
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top