Topic: Using declarations in classes
Author: Jim Gewin <jim@worldnet.att.net>
Date: 1999/08/23 Raw View
The compiler I use (egcs-2.91.60), when compiling the following
short program, diagnoses an access violation, and I'm wondering
if my understanding of using declarations is wrong, or whether
the compiler is incorrect.
I realize that the using declaration is useless here, but the
actual problem came up in a library I didn't write, and is
somewhat more complicated.
Does the using declaration actually make the inherited protected
member unavailable to the derived class? When it's commented out
the program compiles cleanly.
$ cat t.cpp
struct S_base { protected: int x; };
struct S : private S_base
{
int const* get( ) const { return &( this->x ); }
private:
using S_base::x; // <---------------------------------------
};
int const* s_get( S const& s ) { return s.get( ); }
int main( )
{
S s;
s_get( s );
}
$ g++ --ansi --pedantic -Wall t.cpp
t.cpp: In method `const int * S::get() const':
t.cpp:6: member `x' declared private
t.cpp:6: warning: control reaches end of non-void function `S::get()
const'
$
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]