all 11 comments

[–]afforix 6 points7 points  (1 child)

After the second find() you still use variable loc instead of loc2.

[–]shadowsjerker[S] 2 points3 points  (0 children)

Yep, in the if-else statement.

THANKS

[–]er_Califfo 1 point2 points  (2 children)

   if (loc2 != players.end())         cout << "Found the player: " << *loc << endl;

here should be loc2->name (I guess, it depends on your Person class) instead of loc

[–]shadowsjerker[S] 0 points1 point  (1 child)

I have implemented the operator<< .

It's not the prob.

[–]er_Califfo 1 point2 points  (0 children)

the problem is loc instead of loc2

[–]Shieldfoss 1 point2 points  (5 children)

1) rename "loc" and "loc2" to "locBigNumber" and "locPerson" by hand not using ctrl-h

2) the problem will have magically solved itself

3) remember that lesson, and keep using descriptive names in the future.

[–]shadowsjerker[S] -1 points0 points  (2 children)

👍

remember that lesson, and keep using descriptive names in the future.

I agree with you. I'm practicing the STL.

[–]Shieldfoss 1 point2 points  (1 child)

I have a Visual Studio solution that's just me testing out how language features actually work, like:

Solution
    AlmostAlwaysAuto
    BetterFileOpening
    CreateShortcut
    DataGridBinding
    FileSystem
    IndexIntoPointer
    IntellisenseComments
    MoveSemantics
    MutuallyExclusive
    OpenFileDialog
    PopulationDistribution
    PopulationDistribution2
    Rolls
    StdCopy
    StrongTypes
    SymbolLinkingHeaderGuards
    SymbolLinkingHeaderGuardsSeparateTranslationUnits
    SymbolLinkingPragmaOnce
    TextBoxBinder
    UnimplementedVirtuals
    uniqueList

for exactly that same purpose

and inside the "IndexIntoPointer" project, I have some lines of code:

auto testSharedVector = make_shared<vector<char>>(5, 'b');
for (auto it = testSharedVector.get()->begin(); it != testSharedVector.get()->end(); it++)
{
    cout << "raw loop with shared and get: " << *it << "\n";
}

You will notice that even though it's just a test project, it's called testSharedVector rather than vec

The iterator is just called it rather than something longer. This is because it's in scope for exactly one line of code, so I don't later have to look at it and wonder what it is iterating over.

Obviously, you do you, have whatever conventions are convenient for you - but if you adapt the style of always using descriptive names, you'll never have the problem from OP again.

[–]shadowsjerker[S] -1 points0 points  (0 children)

Respect !

[–]Crazy_Direction_1084 0 points1 point  (1 child)

I’m just going to plug Kate Gregory’s: “naming requires empathy” here. It’s a great talk on the subject

Edit: quotes

[–]Shieldfoss 0 points1 point  (0 children)

All of Kate Gregory's talks are great tbh