Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed How to correctly include header files without causing multiple redefinitions( C/C++) ?

+5 votes
asked Dec 12, 2021 by Areeb Sherjil (1,960 points)
closed Dec 12, 2021 by Areeb Sherjil
I have a database which is a 2D-array(matrix) defined in 'database.h' file. This 2d-array is to be accessed in the main.cpp file and another .cpp file which performs calculations on it.

However, when I include it in the main.cpp file and the application.cpp file there is an error: redefined/ multiply defined symbols.... etc.

So, I delete the #include "database.h" from the main.cpp file and now there is another error: "

error: 'Database' was not declared in this scope "

This makes sense as the main.cpp cannot seem to access the database.h file. What is the best strategy to fix this issue? The database.h file has to be include in both main.cpp and application.cpp. I have included appropriate include guards.
closed with the note: This is been fixed by extern for the array. Question answered.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...