Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static variables in abstract base classes

Reply
Thread Tools

static variables in abstract base classes

 
 
pasa_1
Guest
Posts: n/a
 
      11-17-2006
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[i]; }
};

int AbstractBaseClass::a[SZ];

class Derived: public AbstractBaseClass
{
public:
Derived(): AbstractBaseClass() { }
void foo() const
{
int i = 0;
cout << "Derived::foo(): a[" << i << "]: " << a[i] << endl;
}
};

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
static variables in abstract base classes pasa_1 C++ 1 11-17-2006 04:28 PM
Abstract Base classes [op john gagon] FrankLewis Software 0 05-17-2006 09:17 AM
Abstract Base classes - [op john gagon] John Gagon Java 1 05-17-2006 06:40 AM
Abstract Base Classes Ben Finney Python 6 11-14-2005 07:05 AM
Abstract Classes w/o abstract methods DaKoadMunky Java 4 04-20-2004 04:53 AM



Advertisments