-2

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?

user1561358
  • 304
  • 3
  • 14
  • 2
    Are you saying you would want to put just `class C;` in the header, and then `void C::f() {...}` in the source? That won't work. Whoever includes that header would have no idea that the class provides a method named `f`, and so would be unable to call it. – Igor Tandetnik Sep 10 '16 at 22:09
  • Write the code for the program that uses the DLL and it is impossible to not get obvious. – Hans Passant Sep 10 '16 at 23:30
  • You need [The Definitive C++ Book Guide and List](http://stackoverflow.com/q/388242/1889329). **Badly!** – IInspectable Sep 12 '16 at 22:56

1 Answers1

1

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.

JustinCB
  • 513
  • 4
  • 12