Viatcheslav L. Gorelenkov said:
1. This is a template. ( !!!!!
)) ) See source code in my 1-st posting.
I thought the above code was yours... Did I copy it incorrectly?
I
do not give friendship to instantiated template_clase<view_model>, rather it
is friendship to class template_clase<class view_model>. See what is between
the angle brackets <...>. Your can change view_model to C, T, whatever - it
still will compile and work the same way.
Completely and utterly wrong. Observe:
template <class> class template_clase;
class friend_class {
private:
static void f () { }
#ifdef YOURCODE
friend class template_clase<class view_model>;
#else
template <class> friend class template_clase;
#endif
};
template <class view_model>
class template_clase {
public:
void f () { friend_class::f(); } // 18
};
class view_model { };
template class template_clase<view_model>;
template class template_clase<friend_class>; // 23
If YOURCODE is defined, Comeau gives me the following:
"ComeauTest.c", line 18: error: function "<unnamed>::friend_class::f"
is inaccessible
void f () { friend_class::f(); } // 18
^
detected during instantiation of "void
<unnamed>::template_clase<view_model>::f() [with
view_model=<unnamed>::friend_class]" at line 23
In other words, template_clase<view_model> has access to
friend_class::f(), but not template_clase<friend_class>. Therefore,
your code gives friendship only to template_clase<view_model>.
If YOURCODE is *not* defined, Comeau accepts the code. That means that
only my code gives friendship to both template_clase<view_model> and
2. To give friendship to template class foo :
friend class foo<class TTT>; // CLASS TTT
This is true for MS VC++ compiler ( see original posting).
No, it is not. Visual C++ .NET (aka 7.0) gives friendship as ISO C++,
Comeau, GCC 3.2, and I say it should. It accepts (and rejects) the
above code exactly as all these compilers do.
(NB: Visual C++ 6.0 is broken and cannot give friendship to templates.
It rejects the above code regardless of whether YOURCODE is defined.)
- Shane