 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
manfred Guest
|
Posted: Wed Sep 24, 2003 10:48 pm Post subject: returning protected baseclass enum from derivedclass func |
|
|
I have a base class that defines a protected enumeration, and several
derived classes with protected member functions that return this
enumeration type.
VC6 complains when returning Base::enum as return value;
Derived::enum, however, is accepted.
Gnu 2.95 accepts both versions.
who is right?
thanks,
-manfred
class B
{
protected:
enum e { a, b };
};
class D : public B
{
protected:
e func1();
e func2();
};
B::e D::func1() // VC6: 'cannot access protected enum declared in
class B'
{
return a;
}
D::e D::func2() // VC6: compiles ok
{
return a;
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
WW Guest
|
Posted: Fri Sep 26, 2003 10:37 am Post subject: Re: returning protected baseclass enum from derivedclass fun |
|
|
manfred wrote:
| Quote: | I have a base class that defines a protected enumeration, and several
derived classes with protected member functions that return this
enumeration type.
VC6 complains when returning Base::enum as return value;
Derived::enum, however, is accepted.
Gnu 2.95 accepts both versions.
who is right?
thanks,
-manfred
class B
{
protected:
enum e { a, b };
};
class D : public B
{
protected:
e func1();
e func2();
};
B::e D::func1() // VC6: 'cannot access protected enum declared in
class B'
{
return a;
}
D::e D::func2() // VC6: compiles ok
{
return a;
}
|
I would add another question: how can the compiler access the protected
member in an out-of-body declaration *before* it knows it is going to
declare something which actually *does* have access to it?
--
WW aka Attila
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ron Guest
|
Posted: Sat Sep 27, 2003 10:35 am Post subject: Re: returning protected baseclass enum from derivedclass fun |
|
|
| Quote: | class B
{
protected:
enum e { a, b };
};
class D : public B
{
protected:
e func1();
e func2();
};
B::e D::func1() // VC6: 'cannot access protected enum declared in
class B'
{
return a;
}
D::e D::func2() // VC6: compiles ok
{
return a;
}
|
VC is broken. B::e is, of course, accessible for purposes of defining
D::func1(), in the same way that D::func1() is accessible (even though
it's protected) for purposes of its own definition. s.11(5) says:
------
The access control for names used in the definition of a class member
that appears outside of the member's class definition is done as if
the entire member definition appeared in the scope of the member's
class. In particular, access controls apply as usual to member names
accessed as part of a function return type, even though it is not
possible to determine the access privileges of that use without first
parsing the rest of the function declarator.
------
-Ron
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
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
|
|