Reputation: 491
I have to have a structure "configset" in a class-header, something like this:
class A {
public:
static configset *getnext();
}
Of course the compiler complains that configset isn't a type, but it is implemented in another header-file, along with some functions. Because of that I can't just include that header-file, the compiler would throw errors that these functions are defined multiple times. But how can I get the configset in my class-header? Just copying won't work also, since the compiler throws then an error that the structure was defined twice.
Upvotes: 0
Views: 82
Reputation: 11058
Move the implementation of the configset
methods into a separate .cpp (not header) file.
Upvotes: 1
Reputation: 432
Use a forward declaration like so:
// Forward declare configset. Tells compiler that the class/struct is defined in
// another translation unit
struct configset;
class A {
public:
static configset *getnext();
};
Note that this only works as long as you only use pointers to configset.
Upvotes: 1
Reputation: 13526
Forward declare configset
or declare your functions that are defined in a header file as inline
.
Upvotes: 1