Reputation: 10063
I would like to return multiple values in a cross DLL-safe way in C++.
Should I use a stuct/class ?
Upvotes: 1
Views: 895
Reputation: 15566
Although your question is not very clear however, here are a few hints:
A class/struct is meant to group things. Although a struct meant for grouping all the return values can be made but it really depends on how closely related those return values are. This is more a matter of adhering to conventions and OOP principals.
To return multiple values, you can use pointers and references. e.g., following function prototype returns a bool in a conventional way but accepts two pointers as parameters. The objects to which these pointers point to can be changed in the callee function and hence, multiple values can be returned.
Function Prototype:
bool returnValues(int i, char* c, int* result);
Upvotes: 2
Reputation: 7744
Use PIMPL idioms:
In header (dll safe surface):
class Type;
class MyClass
{
public:
int GetNumberOfType();
Type * GetValue(int i) { return this->values[i]; };
protected:
Type ** values;
};
In Source:
#include <Type.h> // common header to real definition and declaration
Upvotes: 0