
April 24th, 2003, 05:06 AM
|
 |
Contributing User
|
|
Join Date: Apr 2003
Location: Manchester, England
|
|
|
Using static modifier with template classes
Hi,
Does anyone have experience of the following? The member attribute counter is declared static so I can keep track of how many variables are in existence. However, this means that it isn't actually defined yet, right?
To do that I have to declare it outside of the class. If this much is true, then the problem I'm having is getting the syntax right on the line that I've commented out, because things are confused by the template <> stuff.
Quite new to this part of C++. Any help much appreciated!
Code:
// Class to store variable information.
template <class PType> class variable
{
// Counter to ensure maximum limit of variables not breached.
static int counter;
public:
// Variable name and value.
char *name;
PType value;
// Constructors.
variable(void);
variable(char *n, PType v);
};
//int variable<PType>::counter;
|