While calling a member function from within another member function, isn't it better to write
this->member_fun( )
rather than
member_fun( ) ?

That would make it very clear that we are calling a member function.

What is the coding standard here? And what could be wrong with the first version?

>What is the coding standard here?
Different people/standards do different things. It's a stylistic issue.

>And what could be wrong with the first version?
Well, it adds unnecessary clutter that distracts from the meat of the code. I would also ask why that information is important enough to add this-> all over the place.

The only time I use this-> is to resolve ambiguous names.

>The only time I use this-> is to resolve ambiguous names.
Same here, and I only have ambiguous names when I'm maintaining code I didn't have control over in writing or when I'm stuck in a corner and can't use unique names. In other words, not often at all. ;)

Different people/standards do different things. It's a stylistic issue.

Yes, but there are some widely accepted ways to do certain things, like using all caps for constants. I was thinking what would that be here.

Well, it adds unnecessary clutter that distracts from the meat of the code. I would also ask why that information is important enough to add this-> all over the place

It may be true that writing this-> could be distracting, but it would help anyone taking a glance. Even in a moderately large class you might have to go back and forth to make see the function definition.

This doubt actually occured to me whan I was writing this code:

bool Bitmap::Display(...)
{
    ClearError( );
    ...
}

I think this would be better

bool Bitmap::Display(...)
{
    this->ClearError( );
    ...
}

And why would that be clearer?
There's no reason at all to do that, unless maybe you've been stupid enough to define one of your class' methods to have an identical signature to a standard library function.
But in that case you should rename your own method...

>Yes, but there are some widely accepted ways to do certain things, like
>using all caps for constants. I was thinking what would that be here.
From what I've seen, the widely accepted way of doing it is to omit this-> .

>but it would help anyone taking a glance.
If you're reading for comprehension (the only case where your situation makes sense), you're doing more than glancing.

>Even in a moderately large class you might have to go back and forth to make see the function definition.
These days it's trivial to find the function definition without scrolling text. IDEs and text editors for programming will generally support this feature.

K, I got my answer... thanks!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.