Why do I need to use :: to denote if a function is a member function but I don't need to do it for the instance variables? I do understand that :: is used to differentiate between standalone and member functions, but I still don't get the variables part. I'll give an example of what I'm talking about.
Shape.h
# pragma once
class Shape {
private:
int height;
int width;
public:
Shape(int height, int width);
}
Shape.cpp
#include "Shape.hpp"
Shape::Shape(int height, int width) {
this->height = height;
this->width = width;
}
int Shape::getHeight() {
return height;
}
int Shape::getWidth() {
return width;
}
Here, I have to to specify the class of the Shape constructor and the getters in order for the compiler to know what I'm talking about. So how come when I do return height; or this->height without specifying class it understands what I'm talking about.