Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I handle name collisions from class variables to function variables and locals? #91

Open
namrog84 opened this issue Jul 2, 2022 · 1 comment

Comments

@namrog84
Copy link

namrog84 commented Jul 2, 2022

This is an arbitrary example but let's say I have a funciton

void SomeClass::SetTarget(AActor* InTarget){
    Target = InTarget;
    ...
    AActor* localTarget = Target; // is local the right prefix for this?
    ...
}

Traditionally in previous teams I've always named the member variable as m_target in this case but I know that's not recommended. I have seen some instances of Epic using My as a prefix but that sometimes doesn't look right either.

I could rename the function parameter to be (AActor* InTarget)

Then what about if I need a local function variable do I name that localTarget?

I've yet to find consistent unreal specific guidelines for dealing with these 3 scopes since I thought I read that using this-> isn't typically recommended?

@namrog84
Copy link
Author

namrog84 commented Jul 2, 2022

In the official UE they say don't have shadowed variables but don't offer reasonable suggested change.
e.g.
https://docs.unrealengine.com/5.0/en-US/epic-cplusplus-coding-standardblueprint-debugging-in-unreal-engine/

Shadowed variables are not allowed. C++ allows variables to be shadowed from an outer scope, but this makes usage ambiguous to a reader. For example, there are three usable Count variables in this member function:

class FSomeClass {
public:
    void Func(const int32 Count) {
        for (int32 Count = 0; Count != 10; ++Count) {
            // Use Count
        }
    }
private:
    int32 Count;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant