This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Using C++ in GCC is OK
Jonathan Wakely <jwakely.gcc@gmail.com> writes:
> Nothing in C++ prevents a "struct" from having member functions,
> constructors, base classes, virtual functions, private members etc.
> If the intention is to impose a distinction between structs and
> classes, based on which keyword is used to define the type, the
> convention should say so. (FWIW, I think that's a reasonable
> convention for a codebase that originated as pure C.)
Well, the convention does in fact say so. But it's true that I didn't
write whether we should permit structs to have methods. I'm inclined
to say no.
>> Our current code always uses the equivalent of an explicit this
>> pointer, except that it is called something else. ÂTherefore I would
>> argue that this is not new. ÂI don't see why using an explicit this->
>> makes code harder to understand in a larger scope; the explicit this->
>> makes it very clear where data is coming from.
>
> If data members have a trailing underscore then isn't it already
> explicit where an unqualified name comes from? foo_ must refer to
> this->foo_, while p->foo_ obviously refers to p's foo_.
Granted.
>> The biggest need for this-> is when calling methods in the current
>> class if the current class happens to be in a template.
>
> The 'this->' is needed when the current class and base class are both
> templates and the name is declared in the base class, and not if it's
> declared in the current class. That is not likely to happen in a
> hurry while the convention is to not define any templates.
Right, but it may happen some day. Also there is the issue of
clarity. I think it is clearer to see this->get() rather than get().
> C++ for-loop scoping means there is no need to reuse the loop variable
> unless you explicitly want to preserve the same value across loops.
> Is the intention to avoid relying on C++ for-loop scoping? If so,
> that should be stated.
I don't think that should be the intention.
Ian