C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

protected et pointeur sur fonction membre

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
loic.actarus.joly@numeric
Guest





PostPosted: Thu Jan 05, 2006 11:29 am    Post subject: protected et pointeur sur fonction membre Reply with quote



Bonjour à tous et bonne année,

Au boulot, on est tombé sur de code comme ça :

class A
{
protected:
int f();
};

class B : public A
{
typedef int(A::*fptr)();
fptr p;
int g()
{
//p = &A::f;
p = &B::f;
}
};

Si on enlève le commentaire, le code ne compile plus, ce qui semble en
accord avec la norme :

11.5 Protected member access
When a friend or a member function of a derived class references a
protected nonstatic member of a base class, an access check applies
in
addition to those described earlier in this clause.[...] If the
access is to form a pointer to member, the nested-name-specifier
shall
name the derived class (or any class derived from that class).

La question que l'on se pose est la motivation de cette règle.
Quelqu'un a une idée ?

Merci,

--
Loïc

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.