C++ two headers with same namespace | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++ two headers with same namespace

I have two header files named aaa.hpp and bbb.hpp, i have namespace named sameName in the both files (aaa.hpp and bbb.hpp) if i run my code, the compiler give an error... please see this code: https://code.sololearn.com/ca1a6A12A92a/#cpp Question: how to specify which namespace is used? sorry for bad english, thanks.

3rd Jan 2021, 7:20 AM
Yousef Ady
Yousef Ady - avatar
1 Answer
+ 4
To run this in Code Playground: Comment out the #include directives for "aaa.hpp" and "bbb.hpp" , then #include <iostream>. Move the lines from aaa.hpp and bbb.hpp above main. This is just like how it's done by #include, all the definitions of the included headers are sort of "added" to the beginning of .cpp content. Can't have 2 function definitions (with same name) under one namespace. Rename one of them. Call `std::cout` rather than just `cout`
3rd Jan 2021, 7:56 AM
Ipang