Class Variables is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Class Variables
| Also Known As | Number of Class Variables (NCV) |
| API ID | CountDeclClassVariable |
| Targets | Architectures Classes Files Project |
| Languages | Basic C# C++ Java Pascal Web |
| Categories | Object Oriented Variable Counts |
| Cost | Query |
| Suites | Lorenz & Kidd |
Number of class variables.
A "class variable" is a static data member — a single value shared by every instance of the class, rather than a separate copy per object.
For example:
class BoatCar: private Car, public Boat, protected DualPurpose {
public:
// Public Instance Function
BoatCar() : Car(4), Boat(), mInWater(false), mColor("Blue") {}
virtual int passengers() const { return 4; }
static int numRegistered() { return sRegistered; }
bool mInWater; // Public Instance Variable
protected:
void toggleInWater(bool inWater) { mInWater = inWater; }
char * mColor; // Protected Instance Variable
friend void init() {}
static int sRegistered;
static double calcSpeed(double distance, double time) {
return distance/time;
}
private:
int mMaxPassengers;
void travel() {}
};
BoatCar declares one static data member, sRegistered, so CountDeclClassVariable = 1.
See Instance Variables for its per-object counterpart.
Also known as Lorenz & Kidd - Number of Class Variables (NCV).
- Basic: Project, Class, Struct
- C#: Project, Class, Struct
- C++: Project, Class, Struct, Union
- Java: Project, File, Class, Interface
- Pascal: Project, Class, Interface
- Web: Project, PHP Class, PHP Interface