Could someone tell me why this function lookup doesn't work (gcc 4.1.2 on
64bit linux)?
struct test
{
const int& func( void ) const {
static const int i = 0;
return i;
}
private:
int& func( void ) {
return const_cast<int&>( static_cast<const test&>(*this).func() );
}
};
int main() {
test t;
int i = t.func(); // error: 'int& test::func()' is private
return i;
}
I'm sure that there is a good reason for it not being able to see the
public const version, but the thing is that I want to give read access to
some boost tuples publicly an write access privately and I would prefer
to keep the "tuple getting" code in one place. I know I could change the
read function's name, or static cast t to <const test&>, but seems a bit
awkward.
What do you think a good solution is?
Cheers,
Brian