scitools.com

← Metric catalog

Const Methods 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.

Const Methods

API ID: CountDeclMethodConst
Languages: C++
Targets: Architectures, Classes, Project

Number of local const methods.

A const method promises not to modify the object it's called on.

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() {}
};

passengers() const is the only const method BoatCar declares, so CountDeclMethodConst = 1.

See Methods for the total across all local methods.


Targets By Language: Configuration: