Topic: Template parameters and privacy
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Mon, 8 Feb 2010 22:28:03 CST Raw View
On 6 Feb., 16:32, heplesser <heples...@gmail.com> wrote:
> Hi!
>
> I would like to seek your assistance in clarifying whether a certain
> piece of code is legal. The code is
>
> --------------------------
> class A
> {
> private:
> struct S_ {
> enum SVE { X, Y, Z };
> };
>
> private:
> template <S_::SVE e>
> double f() const { return 0.0; }};
>
> ------------------------
>
> If I compile this with the IBM xlc++ compiler v 9.0, the compiler
> claims that
>
> line 9.21: 1540-0300 (S) The "private" member "struct A::S_" cannot
> be accessed.
>
> All other compilers I have tested (g++ 4.4.1, icpc 11.1, pgCC 7.1-2)
> accept this code and I believe the code to be correct, as S_ is a
> member of class A, so S_ should be visible anywhere in A, and SVE is a
> public member of S_.
>
> Am I wrong?
You code example looks well-formed and it looks like
a defect in the IBM compiler. As a workaround I suggest
that you try the following
class A
{
private:
struct S_ {
friend class A;
enum SVE { X, Y, Z };
};
private:
template <S_::SVE e>
double f() const { return 0.0; }
};
HTH & Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: heplesser <heplesser@gmail.com>
Date: Sat, 6 Feb 2010 09:32:57 CST Raw View
Hi!
I would like to seek your assistance in clarifying whether a certain
piece of code is legal. The code is
--------------------------
class A
{
private:
struct S_ {
enum SVE { X, Y, Z };
};
private:
template <S_::SVE e>
double f() const { return 0.0; }
};
------------------------
If I compile this with the IBM xlc++ compiler v 9.0, the compiler
claims that
line 9.21: 1540-0300 (S) The "private" member "struct A::S_" cannot
be accessed.
All other compilers I have tested (g++ 4.4.1, icpc 11.1, pgCC 7.1-2)
accept this code and I believe the code to be correct, as S_ is a
member of class A, so S_ should be visible anywhere in A, and SVE is a
public member of S_.
Am I wrong?
Thanks for any advice!
Hans
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]