Name Lookup Happens at Compile Time

The static type (§15.2.3, p. 601) of an object, reference, or pointer determines which members of that object are visible. Even when the static and dynamic types might differ (as can happen when a reference or pointer to a base class is used), the static type determines what members can be used. As an example, we might add a member to the Disc_quote class that returns a pair11.2.3, p. 426) holding the minimum (or maximum) quantity and the discounted price:

class Disc_quote : public Quote {public:    std::pair<size_t, double> discount_policy() const        { return {quantity, discount}; }    // other members as before};

We can use discount_policy only through an object, pointer, or reference of type Disc_quote ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.