Topic: Specialization of a private member function
Author: Thierry Valentin <valentin@t-surf.com>
Date: Tue, 11 Dec 2001 16:51:19 GMT Raw View
Hello,
What does the standard says about specializing a private member
function of a template class ?
Example:
template <typename T> class Example {
public:
...
private:
bool private_member_function() {
return true;
}
};
template<> bool Example<int>::private_member_function() {
return false;
}
Some compilers which support template specialization fail to compile
this, arguing that "private_member_function()" is private.
In other terms: do private access restrictions apply on the
specialization of "private_member_function()" ??
Thanks for your help
--
Thierry VALENTIN email: valentin@t-surf.com
TSURF S.A. tel: (+33)(0)3-83-67-66-29
The gOcad Company fax: (+33)(0)3-83-67-66-34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: jthill_@mac.com (Jim Hill)
Date: Wed, 12 Dec 2001 19:35:56 GMT Raw View
Thierry Valentin <valentin@t-surf.com> wrote in message news:<3C16164B.937C4197@t-surf.com>...
[
template<class> class U { bool f(){return true;}};
template<> bool U<int>::f() {return false;}; // is this C++?
// Some compilers reject this because "U::f is private"
]
The message is wrong. At a guess, it's because the compiler that
spits it doesn't support specialization of individual class template
members, so it doesn't recognize the sequence `template<> bool
U<int>::f()` and complains about the only thing it does understand:
since it doesn't recognize this as a definition, it still regards `f`
as private.
Try this as a workaround. It's ugly, but if you don't need more than
basic member-specialization capability I think it'll serve:
template<class> bool Vf() {return true;}; // main V function
template<class T> class V
{ bool f() { return Vf<T>(); } }; // main V template
template<> bool Vf<int>() {return false;}; // V<int> function
Jim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]