我有一组多个C++类具有相同的接口(但不是彼此派生)。我试图包装这些,使他们在.NET中可用。C++/CLI模板包装轮
我现在有限定用C/C++的#define包装类的方法,然后我可以随后实例化类用代码
一个简单的线然而我不能调试此。理想情况下,我希望能够使用通用或模板。不过,我不能在通用内部使用C++类型,这将是解决此问题的最终方法。
有没有人有任何想法,我怎么能做到这一点,而不使用可怕的宏?
编辑:
确定这里是我写的模板类的一个实例:
template< typename CPPResamplerClass >
ref class TResampler
{
CPPResamplerClass* pResampler;
public:
TResampler(int inputSampleRate, int outputSampleRate, int bufferLen) :
pResampler(new CPPResamplerClass(inputSampleRate, outputSampleRate, bufferLen))
{
}
~TResampler()
{
this->!ResamplerName();
}
!TResampler()
{
if (pResampler)
{
delete pResampler;
pResampler = nullptr;
}
}
property int HistorySize
{
int get()
{
return pResampler->HistorySize();
}
}
array<float>^ ResampleAudio(array<float>^ in)
{
pResampler->Get
array<float>^ out = gcnew array<float>(in->Length);
cli::pin_ptr<float> pIn = &in[0];
cli::pin_ptr<float> pOut = &out[0];
unsigned int inLen = in->Length;
unsigned int outLen = out->Length;
if (pResampler->ResampleAudio(pOut, outLen, pIn, inLen))
{
System::Array::Resize(out, outLen);
return out;
}
return nullptr;
}
};
typedef TResampler<::Vec::SpeexResample> SpeexResample;
那么我想从C#访问此然而SpeexResample
不存在。这可能是因为我正在使用typedef ...
这个问题*绝对*需要一些示例代码。作为高级代表用户,您应该知道[mcve]是什么... –
模板是C++的细节,对任何其他.NET语言都没有用处。改为使用'generic'关键字。 –
@HansPassant:但我不能使用C++类型作为泛型类的参数...我可以吗?如果我可以......你能解释一下,因为那是我问题的症结所在! ;) – Goz