c++ - Private template classes/structs visibility -



c++ - Private template classes/structs visibility -

i don't understand why in next code, allowed create function print_private_template while compiler complains print_private_class:

#include <cstdio> class { private: template <unsigned t> struct b { }; struct c { }; public: template <unsigned t> b<t> getab() { homecoming b<t>(); } c getac() { homecoming c(); } }; template<unsigned t> void print_private_template(const a::b<t> &ab) { printf("%d\n", t); } void print_private_class(const a::c &ac) { printf("something\n"); } int main(int, char**) { a; print_private_template(a.getab<42>()); print_private_class(a.getac()); homecoming 0; }

is expected behaviour? compiler bug/extension?

just clear, goal create compiler error on both usage of print_private_template , print_private_class.

comeau give error (when comment out print_private_class function , phone call in strict c++03 mode.

comeautest.c(31): error: class template "a::b" (declared @ line 7) inaccessible void print_private_template(const a::b &ab) ^ detected during instantiation of "print_private_template" based on template argument <42u> @ line 45

g++ 4.5 on windows not study error -std=c++ -wall -pedantic though.

your class a::c , class template a::b<t> both have same visibility other normal members. hence, both print_private_class , print_private_template require diagnostic.

11.8 nested classes [class.access.nest]

1 nested class fellow member , such has same access rights other member. members of enclosing class have no special access members of nested class; usual access rules (clause 11) shall obeyed.

c++ templates private-members

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -