This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y>
- From: "sean dot gies at discreet dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Sep 2003 01:47:02 -0000
- Subject: [Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12429
Summary: Template class Foo<X> cannot access private members of
Foo<Y>
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sean dot gies at discreet dot com
CC: gcc-bugs at gcc dot gnu dot org
Member functions of template classes cannot access protected or private members of a different
specialization of itself, nor can a friendship be declared to allow the access.
The only workaround involves hacking the public interface of the template class.
For example, private member function Bar(int) of class Foo<float> cannot call Bar(int) of class
Foo<int>:
template <class T> class Foo {
template <class F> friend class Foo<F>; // This attempted work-around also fails
void Bar(int x=0) {if (x<4) Foo<int>().Bar(x+1);}
public:
void Test() {Bar();}
};
int main(int argc, char** argv) {
Foo<float>().Test();
}