0
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int Answer;
struct _pair {
    struct _pair(int a) : value(a), cnt(1) {}
    unsigned int value;
    unsigned int cnt;
    };


int main(int argc, char** argv)
{

    return 0;
}

this code occurs error : "error: expected unqualified-id before 'int' struct _pair(int a) : value(a), cnt(1) {}"

It makes no error on VS2017, but it makes an error on GCC compiler.

Lam Le
  • 1,489
  • 3
  • 14
  • 31
David Oh
  • 23
  • 5
  • 7
    There shouldn't be `struct` in `struct _pair(int a) : value(a), cnt(1) {}`. – François Andrieux Oct 02 '17 at 17:31
  • 2
    Also: `using namespace std;` in combination with a symbol prefix `_` might give you all kinds of weird compiler errors. – user0042 Oct 02 '17 at 17:42
  • That's a global namespace underscore prefix, so `using namespace std;` isn't required to wreak havoc. It just makes things worse. More info here: [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) – user4581301 Oct 02 '17 at 18:30

1 Answers1

5

The constructor doesn't need the struct qualifier:

#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int Answer;
struct _pair {
   _pair(int a) : value(a), cnt(1) {}
    unsigned int value;
    unsigned int cnt;
};
Daniel Trugman
  • 8,186
  • 20
  • 41