Importing an existing class

I have been programming for about 1.5 years in school now. I am good at C++, C#, and Java. I am having a little issue with importing an existing class that I built into my current project.
I'm using Code:Blocks for my IDE when I write in C++. I have created a project in Code::Blocks that I have built a header class to use and the main() can, after making an instance of that class, use the class's public member methods with the DOT operator.
I have another project that I created that I have added to the same workspace as the new project is in. The problem I'm having is how do you add the header class from the first project to the new project without coping and pasting the code into a newly added class. Is there not a way to just import the namespace I created in the first project to the new project so that I can create an instance of that class without rewriting the class I already had created in the first project.
If not what is the purpose of creating a namespace if you have to copy and paste the code from the namespace you want to reuse in a new project.

I believe I found to be what is the only way.

You have to copy the file you want to add and add it to the file directory of the project you want to use it in. Then right click the project name in Code::Blocks and add the file you added to the the file in the file explorer.

If anyone knows of an easier way, such as creating a project that only contains a namespace that you create and just use the using namespace directive in your code of any new project.
You can add directory to search for headers in compiler settings. If your code contains implementation files too, compile them to object file(s) and link them to your program.

what is the purpose of creating a namespace
To separate names, for better categorisation and avoiding name clashes.
Thank you MiiNiPaa
Topic archived. No new replies allowed.