Topic: Using declaration for class members
Author: "Sebastian Moleski \(SurakWare\)" <smoleski@surakware.com>
Date: Sat, 20 Jan 2001 12:05:15 GMT Raw View
Hi,
I wondered whether the following is legal C++. gcc gives an error while
Borland C++ accepts it. I couldn't find much in the Standard, the examples
usually involved only either namespaces or using declarations within class
definitions.
Here's the code:
class A {
class B { };
};
using A::B; // valid using declaration?
B b; // valid declarator for b?
TIA,
sm
---
[ 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 ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: graywane@NOT-AT.home.com (graywane)
Date: Mon, 22 Jan 2001 19:13:04 GMT Raw View
In article <94b6qf$pgh$00$2@news.t-online.com>:
> Here's the code:
>
> class A {
> class B { };
> };
>
> using A::B; // valid using declaration?
>
> B b; // valid declarator for b?
g++ isn't always a good platform to decide whether or not something is
legel. For instance, section 7.3.3 paragraph 3 on page 115 of the standard
has the following example:
struct B {
void f(char);
void g(char);
enum E { e };
union { int x; };
};
struct D : B {
using B::f;
void f(int) { f('c'); } // calls B::f(char)
void g(int) { g('c'); } // recursively calls D::g(int)
};
Which g++ gives the following error message for:
test.C:13: cannot adjust access to `void B::f(char)' in `struct D'
test.C:11: because of local method `void D::f(int)' with same name
Having said that, I think the using directive in your code segment should be
accepted by a conforming compiler. I think g++'s error message indicates a
set of rules for using directives that is more restrictive than the standard:
test.C:6: A' is not a namespace
Just my $.02
---
[ 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 ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Andrei Iltchenko" <iltchenko@yahoo.com>
Date: Mon, 22 Jan 2001 19:20:40 GMT Raw View
> I wondered whether the following is legal C++. gcc gives an error while
> Borland C++ accepts it. I couldn't find much in the Standard, the examples
> usually involved only either namespaces or using declarations within class
> definitions.
>
> Here's the code:
>
> class A {
> class B { };
> };
>
> using A::B; // valid using declaration?
This is not allowed by the Standard, because "A using declaration for a
class member shall be a member-declaration" See 7.3.3/5. Besides, the
name A::B is not accessible in the scope where the using declaration
occurs.
>
> B b; // valid declarator for b?
This is automatically not valid too, as the class name B is not visible
in this scope.
Regards,
Andrei Iltchenko
Brainbench MVP for C++
http://www.brainbench.com
---
[ 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 ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]