[Bug c++/12429] New: Template class Foo<X> cannot access private members of Foo<Y>
sean dot gies at discreet dot com
gcc-bugzilla@gcc.gnu.org
Sat Sep 27 03:14:00 GMT 2003
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();
}
More information about the Gcc-bugs
mailing list