I am writing a node addon that builds with node-gyp and I want to link with libraries from a large project (kaldi-asr) that is build using Makefiles.
It is infeasible for me to replicate the Makefile structure in the binding.gyp file, so I created an abstract class, and another class that extends it. This allows me to use the object having only the declaration of the abstract class that does not depend on any header or source of the kaldi project.
class DecoderBase {
public:
// This method is a trick to make this header file
// independent of the rest of kaldi.
//
// The implementation of this method will simply create
// in instance of Decoder, that uses the kaldi types.
//
// The Decoder inherits DecoderBase, so it can
// be casted to DecoderBase, this class by the other
// only uses the standard C++ types
static DecoderBase* CreateNew();
// give the ability to destroy an object from a pointer
// to this abstract class.
// warning: deleting object of abstract class type 'TrecDecoderBase'
// which has non-virtual destructor will cause undefined behaviour.
virtual void Destroy() = 0;
virtual void InitDecoder() = 0;
virtual void DeinitDecoder() = 0;
virtual ~DecoderBase();
};
If the file is included more than once the compiler complains about class redefinition.
If I remove the definitions from the virtual methods it fails with no typeinfo for class.
Aparently it works if I leave as is and add #pragma once
, is this enough, what if I include the header from different code units?
Is there a way to declare pure virtual functions without creating a class definition?