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