Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scope resolution operator

25 views
Skip to first unread message

Doug Mika

unread,
Apr 9, 2015, 6:44:55 PM4/9/15
to
I am having problems interpreting the following:

duckBilledP.Mammal::Animal::Age=25;

why not simply
duckBilledP.Animal::Age=25;
?

where we are given:
class Animal{
public:
int Age;
};

class Mammal:public Animal{};
class Platypus:public Mammal{};

int main(){
Platypus duckBilledP;
duckBilledP.Mammal::Animal::Age=25;
//duckBilledP.Animal::Age=25; //why wouldn't this work?
}

Victor Bazarov

unread,
Apr 10, 2015, 9:17:02 AM4/10/15
to
Actually, given the hierarchy the simple

duckBilledP.Age = 25;

ought to do. However, if somewhere in the derived classes there were a
member 'Age', the scope resolution would help avoiding ambiguity, IIRC.

V
--
I do not respond to top-posted replies, please don't ask
0 new messages