CPP lint: Can you enforce use of this for class variables?
Asked Answered
B

0

0

Is there a lint script that will enforce use of this for class variables?

Ex -

class A {
    int var1;

    void func() {
        return var1;
    }
}

should be -

class A {
    int var1;

    void func() {
        return this->var1;
    }
}
Bekelja answered 10/1, 2018 at 11:13 Comment(7)
"should be" - Is this a coding style requirement or some misguided assumption?Clinkscales
basically there should be clear distinction between class and local variables. One way to do that is to name class variables with some rule(like adding an underscore). But if you can enforce this, that shouldn't be requiredBekelja
You don't think lugging this-> around is kind of a "naming rule"?Clinkscales
Ofcourse it is. But I find that more clear than naming variables correctly.Bekelja
Having to type an extra 6 characters just to access a member variable sounds like a frustrating ruleBurge
Anyway, do you think it's unnecessary or is there a better way?Bekelja
I'm pretty sure that Lint only provides rules for suggestions to improve your code.Retrochoir

© 2022 - 2024 — McMap. All rights reserved.