我正在尝试对模板类进行typedef接受默认的构造函数参数,但是我遇到了错误。

这很好用:

typedef TransientWriter<DDS::NetAcquire::MeasurandMetaData,
::NetAcquire::MeasurandMetaDataTypeSupport_var,
::NetAcquire::MeasurandMetaDataTypeSupportImpl,
::NetAcquire::MeasurandMetaDataDataWriter,
::NetAcquire::MeasurandMetaDataDataWriter_var,
::NetAcquire::MeasurandMetaDataDataReader,
::NetAcquire::MeasurandMetaDataDataReader_var> Writer;


但是,我希望此类通过构造函数采用默认的字符串参数。我试过了:

typedef TransientWriter<DDS::NetAcquire::MeasurandMetaData,
::NetAcquire::MeasurandMetaDataTypeSupport_var,
::NetAcquire::MeasurandMetaDataTypeSupportImpl,
::NetAcquire::MeasurandMetaDataDataWriter,
::NetAcquire::MeasurandMetaDataDataWriter_var,
::NetAcquire::MeasurandMetaDataDataReader,
::NetAcquire::MeasurandMetaDataDataReader_var>
(::NetAcquire::MeasurandMetaDataTopic) Writer;


这给了我一个奇怪的错误:error: expected initializer before ‘Writer’

我也尝试过这样:

typedef TransientWriter<DDS::NetAcquire::MeasurandMetaData,
::NetAcquire::MeasurandMetaDataTypeSupport_var,
::NetAcquire::MeasurandMetaDataTypeSupportImpl,
::NetAcquire::MeasurandMetaDataDataWriter,
::NetAcquire::MeasurandMetaDataDataWriter_var,
::NetAcquire::MeasurandMetaDataDataReader,
::NetAcquire::MeasurandMetaDataDataReader_var>
Writer(::NetAcquire::MeasurandMetaDataTopic);


这给了我error: typedef ‘JARSS::DDS::Object::NetAcquire::MeasurandMetaData::Writer’ is initialized (use decltype instead)

我会在这个typedef上出错吗?有什么建议我可以代替吗?

谢谢。

最佳答案

在C ++中无法做到这一点。

考虑创建一个新类,向TransientWriter<DDS::NetAcquire::MeasurandMetaData, ::NetAcquire::MeasurandMetaDataTypeSupport_var, ::NetAcquire::MeasurandMetaDataTypeSupportImpl, ::NetAcquire::MeasurandMetaDataDataWriter, ::NetAcquire::MeasurandMetaDataDataWriter_var, ::NetAcquire::MeasurandMetaDataDataReader, ::NetAcquire::MeasurandMetaDataDataReader_var>的构造函数添加重载或创建工厂函数。

09-10 04:16