c++模板里展开变长参数在项目里的应用

张开发
2026/4/14 16:33:03 15 分钟阅读

分享文章

c++模板里展开变长参数在项目里的应用
put是重载函数有多个只接收一个参数的。class DataExternalizer{};///code{.unparsed} ///此函数的功能 /// /// 写入数据。这些参数的类型要符合Bentley::DataExternalizer::put的各个重载函数 /// ///endcode ///return true:成功 false:失败 ///author Simon.Zou date 2026/04/09 templatetypename ...Args static bool SetData( DgnPlatform::EditElementHandle eeh, UInt16 majorId,// HchxElemSideDrawing_XAMajorId, UInt16 minorId,// HchxElemSideDrawing_XAMinorId, UInt32 xaId,// HchxElemSideDrawing_XaId_General Args... param ) { Bentley::DataExternalizer sink; int dummy[] { (sink.put(std::forwardArgs(param)),0)... }; std::ignore dummy; XAttributeHandlerId xAttributeHandlerId(majorId, minorId); UInt32 xAttrId xaId; return BentleyStatus::SUCCESS eeh.ScheduleWriteXAttribute(xAttributeHandlerId, xAttrId, sink.getBytesWritten(), sink.getBuf()); } 引用 bool MiscUtil::SetComponentType( EditElementHandleR eeh, ///IN const ObjectType oType, ///OUT const std::wstring linkDataStr,// StringUtil::s2ws(LinkData::CreateFakeJsonstr()) const std::wstring uuid// L123, ) { int version 1; WString str0 (const_castObjectType(oType)).GetStr().c_str(); WString str1 uuid.c_str(); WString str2 linkDataStr.c_str(); XAttributeHandlerId xAttributeHandlerId HCHXKERNEL::GetLinkDataXAId();//(HchxElem106XAMajorId, HchxElem106XAMinorId); UInt16 majorId xAttributeHandlerId.GetMajorId(); UInt16 minorId xAttributeHandlerId.GetMinorId(); UInt32 xaId 0; //在这里调用 return MiscUtil::SetData( eeh, majorId, minorId, xaId, version, str0, str1, str2 ); }下面的代码C14还不支持 templatetypename ...Ts void printNumber(Ts... nums) { ((std::coutnums),...); std::cout std::endl; } void main1124ff() { printNumber(1, 2, 3, 4, 5); } error C3520: “nums”: 必须在此上下文中扩展参数包 参见对正在编译的函数 模板 实例化“void printNumberint,int,int,int,int(int,int,int,int,int)”的引用 error C2059: 语法错误:“...”

更多文章