user1561358 user1561358 - 15 days ago 6
C++ Question

Defining functions of a class in .cpp of a Dynamic-link Library

Recently I started working with c++ and I was wondering.
If I'm working on DLL, I first define all the classes and and their functions in the header and then write their functionality in

.cpp
file in the same project.
But what if I instead defined only the classes themselves and then defined their functions in
.cpp
file.

It would somewhat reduce the amount of code required and the code would be more readable with much less
::
notations.

Is something like that possible?

Answer

You have to define your classes(structs, etc) and declare your namespace(s) and functions in your header. That being said, you can use

using namespace <your_library_namespace>;

And then everything in your source file in <your_library_namespace> won't need to use <your_library_namespace>:: before everything.

Comments