0

I accidentally compile a code that looks like this:

#include <iostream>
using namespace std;

struct Thing {
    Thing(const int a) : a(a) {};
    int a = -1;
    void set_a(const int a) { this->a = a; };
};

void strange(Thing& t) {
    t.set_a(-1), 2, t.set_a(3); // <-- ?
}

int main() {
    Thing t(3);
    strange(t);
    std::cout << t.a; //output 3
    return 0;
}

But why does it compile in the first place ? What does , mean in the declaration of the function strange ?

Run it live here

Deewy
  • 245
  • 1
  • 8
  • _in the declaration of the function_ you mean definition? –  Dec 29 '17 at 12:58
  • @manni66 Without previous declaration, a definition of a function declare it at the same time. So, this could be valid in this context ;) – Stargateur Dec 29 '17 at 12:59
  • I am probably missing something obvious, I don't understand why this is flagged as duplicate. – Deewy Dec 29 '17 at 13:00
  • 2
    Look at this answer https://stackoverflow.com/a/19198977/487892 instead of the accepted one. – drescherjm Dec 29 '17 at 13:06
  • Thanks, I didn't scrolled enough. There should be a functionality like `Community accepted answer`. – Deewy Dec 29 '17 at 13:10

0 Answers0