Reputation: 14075
I have a C++ class Alice
that must be exported from a dll. It has references to objects of other custom classes like Bob
.
When I use my dll in another exe project I don't want and don't need to know about Bob
(even if the reference is public).
I thought of making something like HANDLE
in WinApi out of Bob's objects (like IntPtr in C#).
Reasons: I need to include Alice.h
in my exe project to be able to use Alice right ? So I want to expose only 1 header file and not Bob.h
and Chellsie.h
and Detlef.h
and ...
HANDLE
a good idea ? Or can I avoid my problem below in a different way ?
class __declspec(dllexport) Alice
{
public:
Bob bob;
Chellsie chellsie;
Detlef detlef;
};
class __declspec(dllexport) Alice
{
public:
HANDLE bob;
HANDLE chellsie;
HANDLE detlef;
};
Upvotes: 2
Views: 174
Reputation: 258578
Sure Alice needs Bob, Bob is an integral part of Alice. It's composition. If you held a pointer to a "Bob", you'd be able to use a forward declaration, but as-is now, a full definition of Bob is required:
#include "Bob.h" // required, Bob must be known
class __declspec(dllexport) Alice
{
public:
Bob bob;
Chellsie chellsie;
Detlef detlef;
};
vs
class Bob; // declaration is enough
class __declspec(dllexport) Alice
{
public:
Bob* bob;
Chellsie chellsie;
Detlef detlef;
};
Upvotes: 4