0

I want to create a project, I have 3 files, a test.cpp, something.h and a something.cpp. here they are:

test.cpp:

#include <bits/stdc++.h>
#define f cin
#define g cout
#include "something.h"
using namespace std;

int main(void)
{
    int x;
    register(x);
    return 0;
}

something.h:

#ifndef __SOMETHING__H_
#define __SOMETHING__H_
#include <bits/stdc++.h>

void register(int x);
#endif

something.cpp:

#include "something.h"

void register(int x)
{
    std::cout << x << '\n';
}

And here is the error I get:

In file included from test.cpp:4:0:
something.h:5:15: error: expected unqualified-id before ‘int’
 void register(int x);
               ^~~
something.h:5:15: error: expected ‘)’ before ‘int’
test.cpp: In function ‘int main()’:
test.cpp:10:15: error: ISO C++ forbids declaration of ‘x’ with no type [-fpermissive]
     register(x);
               ^
test.cpp:10:15: error: redeclaration of ‘int x’
test.cpp:9:9: note: ‘int x’ previously declared here
     int x;
         ^
In file included from something.cpp:1:0:
something.h:5:15: error: expected unqualified-id before ‘int’
 void register(int x);
               ^~~
something.h:5:15: error: expected ‘)’ before ‘int’
something.cpp:3:15: error: expected unqualified-id before ‘int’
 void register(int x)
               ^~~
something.cpp:3:15: error: expected ‘)’ before ‘int’

Why does it tell me that I redefine x? When I just want to call register with it's value.

C. Cristi
  • 569
  • 1
  • 7
  • 21
  • 3
    Unrelated: [Why should I not `#include `?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Ted Lyngmo May 06 '20 at 13:21
  • 3
    Side comments: [don't](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) `#include `, [don't](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) `using namespace std`, and [cut out](https://stackoverflow.com/questions/14041453/why-are-preprocessor-macros-evil-and-what-are-the-alternatives) the unnecessary use of macros – Cory Kramer May 06 '20 at 13:22
  • `#define g cout` could also cause you problems if register was not a reserved word. – drescherjm May 06 '20 at 13:47

1 Answers1

5

register is a reserved word in C++. Therefore, you have to give another (unreserved) name.

more information: Register keyword in C++ - Stack Overflow

MikeCAT
  • 73,922
  • 11
  • 45
  • 70