The Background: I offer a virtual file structure over two different technologies: FUSE and MTP. Since both frameworks need different interfaces, I ve created two base classes which serve these interfaces. The FUSE famework only knows the IFuseFile
interface while the MTP framework only knows the IMTPFile
interface. These base classes have pure virtual methods, which are implemented by the derived class.
The Problem: When implementing it straight forward, I get a "request for member IsWriteable is ambiguous"
by the compiler (see example source).
The Solution: When searching for a solution, I only found the diamond pattern. But I have only common pure virtual methods, no common classes. For me a simple using BASE::method
does the trick.
The Question: Since I used the using BASE::method
only for hidden methods before, I cannot explain why this code solves my problem. Can you explain it? Is this only a GCC bug/feature?
The Example:
class IFuseFile
{
virtual bool IsWriteable() const = 0;
public:
int HandleReadRequest( struct fuse_data* pData )
{
if( !IsWriteable() ) return -EACCESS;
...
}
}
class IMTPFile
{
virtual bool IsWriteable() const = 0;
public:
int ReadData( const char* pBuffer, int iSize )
{
if( !IsWriteable() ) return -1;
...
}
}
class PcComFile : public IFuseFile, public IMTPFile
{
using IFuseFile::IsWriteable;
using IMTPFile::IsWriteable;
}
class LogFile : public PcComFile
{
bool IsWriteable() const override { return true; }
}
class StatusFile : public PcComFile
{
bool IsWriteable() const override { return true; }
}