-5

In the below code I could not understand what does :: before array add[i] means. Can anyone give me a general idea of what does this means in c++ if added before array data structure?(This is general for reference only code)

#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)

    FOR(i, 1, n) {
        scanf("%d %d", &x, &y);
        double add = dist(Tx, Ty, x, y);
        all += add * 2;
        suff[i] = pre[i] = dist(Cx, Cy, x, y) - add;
        ::add[i] = dist(Kx, Ky, x, y) - add;
    }
FSI
  • 17
  • 6
  • 4
    What is that `FOR` macro you seem to be using? If you're going to write real, idiomatic, C++ (instead of basically writing C in C++) you shouldn't use macros like that. – Dai Nov 01 '21 at 10:13
  • 1
    `::` indicates that `::add` resides in global scope. – πάντα ῥεῖ Nov 01 '21 at 10:15
  • 1
    `::` before a symbol indicates the global namespace, so it is referring to a different `add` to the one declared just above. – janm Nov 01 '21 at 10:16
  • Guys, that FOR is just for reference only added define statement now, I don't think it even matters in the reference of this question.....as I wanted general ans didn't wanted to post whole code – FSI Nov 01 '21 at 10:21

1 Answers1

1

It means it is referencing the array add defined in the global namespace rather than the local variable add defined in the block of code following the FOR macro.

Usually you'd just give the local variable a different name. And most times you wouldn't have a global mutable variable either.

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171