I need to implement the following interface
struct mutex;
struct interface
{
//...
mutex& getMutex();
};
Intuition would I could use using mutex = ParticularMutex
in my implementation, but gcc tells me otherwise:
error: conflicting declaration ‘using mutex = ’
error: ‘class mutex’ has a previous declaration as ‘class mutex’
I am not defining anything twice, only declaring twice, as usual when forward declaring, so
interface
?interface
have been defined? with template <typename mutex>
?It does not work because the forward declaration struct mutex;
tells the compiler that mutex
is a new type. With using
you are then creating a type alias, which means it's not a new type (as promised to the compiler), but an alias to an existing type.
No.
Yes.
What you could do is:
struct mutex : ParticularMutex {
using ParticularMutex::ParticularMutex; // inherit constructors
};
Which does define a type derived from ParticularMutex
which is hopefully compatible enough. Of course, this is a new type which might lead to other problems.