Jump to

v04-l2-resolutionOp

Which type of operation is not permitted by the scope resolution operator :: in C++ ?

???

You can access a shadowed attribute in an object's method :

class Object {
    int x;
    void method(int x) {
        x;          // -> argument of method
        this->x;    // -> attribute of the object
        Object::x;  // -> attribute of the object too !
    }
};

You can access a redefined attribute from a children class :

class Parent {
protected:
    int x;
};
class Children : public Parent {
    int x;  // x here is redefined
    void method() {
        x;          // -> Children's attribute
        Parent::x;  // -> Parent's attribute
    }
};

You can inherit all constructors from a parent class :

#include <utility>

class Parent {
    int x;
    double y;
public:
    // Base constructor
    Parent(int x, double y) : x(x), y(y) {}
    // Default constructor
    Parent() : x(0), y(0) {}
    // Copy constructor
    Parent(const Parent& other) : x(other.x), y(other.y) {}
    // Move constructor
    Parent(Parent&& other) : x(std::move(other.x)), y(std::move(other.y)) {}
};
class Children : public Parent {
    using Parent::Parent; // Inherit all constructors from Parent !
};

But you cannot access a shadowed variable defined in any parent scope

int i = 1;
{
    int i = 2;
    // Cannot access the first i (=1) here !
}