#ifndef A
//includes
namespace A
{
class A
{
//variables and prototypes
};
namespace AB
{
class B
{
//variables and prototypes
};
class AB : A, B
{
//variables and prototypes
};
};
};
#endif
a.cpp
1 2 3 4 5 6 7 8 9
#include "a.h"
namespace A
{
//A's functions and operators
namespace AB
{
//B's and AB's functions and operators
};
};
Do I need to do anything to get them to compile to a DLL Library?
And how would I call them from the library?
To call them from another application, you could load the DLL file using LoadLibrary() and get a pointer to the function using GetProcAddress(). Then you would have to surround the code in the DLL file in a extern"C" block to prevent name scrambling.
However, there is a simpler way to go about things. When you build your DLL, you should also get an import library (with a .lib or .a extension, I believe). You can link to this as if it were a static library to provide access to the content of the DLL files. However, you have to take what Framework said a little further. The DLL must have all its symbols marked as __declspec(dllexport), but the same symbols must be marked as __declspec(dllimport) in the project using the DLL. I answered a previous thread on this topic and I'll try and find it now so you can see the details.
__declspec(dllexport) will cause name mangling. Also, extern "C" is not needed, and linking the .lib is completely overkill. All you need is a .def file that looks like this:
so I compile my .cpp and .h to .DLL and make a .def file to allow organised loading?
would this allow me to make a framework? allowing me to organize the classes and functions through namespaces for ease of use?
Slightly related, I'm a graphics programmer (rather new to C++ used to use C#) and my current goal is to create a number of classes and to simplify the loading, storing, modification and drawing of models and images.
This being the case I will have a large number of classes, structs (I use C# syntax of class for function heavy, struct for data storage) and functions. So organizing them via namespaces is rather important.
EDIT: MY MISTAKE!
I read up on def files a bit,
So I compile my cpp and h files using a .def file which will compile to DLL with a lib file.
I'd still like to know about if this would allow me to organize with namespaces
Have you heard of SFML? ;)
Also, classes and structs and unions are all exactly the same in C++ except that classes start off with private access by default, structs and unions start public, and all data members in a union share the same memory.
If you don't want to dynamically link the DLL like I did then you would indeed need to statically link with the .lib file and the header file to use namespaces, etc.