Scope of variables here?

Just curious what would be the term for the scope of these variables (this was pulled from the tutorials here)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// example: class constructor
#include <iostream>
using namespace std;

class Rectangle {
    int width, height;
  public:
    Rectangle (int,int);
    int area () {return (width*height);}
};                   
                        //v      v
Rectangle::Rectangle (int a, int b) { //  <---- Those
  width = a;            //^      ^
  height = b;          // |      |
}

int main () {
  Rectangle rect (4,5);
  Rectangle rectb (5,6);
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}

Last edited on
They are in the scope of the constructor.

like:

1
2
3
4
5
double wibble(double a, double b) {

    return a*b;

}


a and b would be function-scope.
Last edited on
Topic archived. No new replies allowed.