Group: comp.lang.c++
From: Brian Tyler
Date: Tuesday, April 08, 2008 4:20 PM
Subject: Re: Function lookup problem

On Tue, 08 Apr 2008 12:48:08 -0700, Chris Thomasson wrote:

> "Brian Tyler" wrote in message
> news:AaPKj.44228$kN5.9791@newsfe1-gui.ntli.net...
>> Could someone tell me why this function lookup doesn't work (gcc 4.1.2
>> on 64bit linux)?
> [...]
>>
>>
> Your calling func on a non-const test object. Try this to force it work:
> ______________________________________________________ struct test
> {
> const int& func( void ) const {
> static const int i = 0;
> return i;
> }
>
> private:
> int& func( void ) {
> return const_cast( static_cast(*this).func() );
> }
> };
>
> int main() {
> test t;
> test const& tx = t;
> int i = tx.func();
>
> return i;
> }
> ______________________________________________________
>
>
>
>
>> What do you think a good solution is?
>
> Rename your private function. I personally like to add either a 'sys_'
> or a 'prv_' prefix to my private function names. In other words use
> 'test::sys/prv_func()' instead...

Thanks for the tip Chris. I like the idea of identifying the private
functions with a prefix.

Brian

Safety Articles | Usenet Groups | Usenet News | Bluegrass