1

I'm trying to separate my code into headers and cpps
I made a .h and .cpp for every class I had
but I have no idea where to put the functions (that aren't in classes) and the global variables
I tried putting them in main but it didn't work
I also tried putting them in every cpp that needed them but I got the error of (Multiple Definition of the variable)
What to do?

1 Answer 1

2

In the .h:

extern int myGlobal; int myFunction(int arg); 

In one of the .cpp files:

int myGlobal; int myFunction(int arg) { return arg + 5; } 

You can split stuff across multiple .cpp files, just don't define anything in more than one place. If you put a definition in a .h file, and include it multiple times, you get multiple (conflicting) definitions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.