gcc 编译具有大量模板参数的模板化类时出错

发布于 2024-12-04 10:25:04 字数 5316 浏览 2 评论 0原文

我在编译将模板类嵌套在其他模板类中的代码时遇到问题。名为 MyClass 的主要模板类有 50 个模板参数,它们接受名为 null_type_nn 的默认类类型,不执行任何特定操作。

我的模板参数全部以“_”字符开头,如下所示

     template< 
         class T0=null_type_0
       , class T1=null_type_1
       , ...
       , class T50=null_type_50
     > MyClass;

     typedef MyClass< _MyClassB, _MyClassC > _MyClass1;
     typedef MyClass< _MyClassD, _MyClassE > _MyClass2;
     .....
     typedef MyClass< _MyClass1, _MyClass2, _MyClass3 , ..._MyClass50> my_type_a;

如果我不调用类的某个成员函数,则不会出现以下错误;如果我只是构造一条消息,然后访问/使用其数据成员之一,我就没有问题。

我可以做些什么来解决它或帮助编译器完成其工作?

       : Assembler messages:
       :8851: Error: symbol `_ZN12mine_structIL10EncodingID5015ELS0_1011E11
       AsciiStringLS0_1115E23AsciiAlphaNumericStringLS0_1130ES2_LS0_1019E6S
       Int16LS0_1066ES2_LS0_5030E11mine_unionILm1ES_ILS0_5042ELS0_15ES1_
       LS0_16404E11mine_arrayILm4ES_ILS0_20ELS0_18ES2_LS0_1078ES3_LS0_2ES3_
       LS0_19E5Dec32LS0_16E6SInt32LS0_64005E12mine_null_5LS0_64006E12
       mine_null_6LS0_64007E12mine_null_7LS0_64008E12mine_null_8LS0_64009E12
       mine_null_9LS0_64010E13mine_null_10LS0_64011E13mine_null_11LS0_64012E13
       mine_n...// continues..it is a very big error!

完整的错误日志如下

:汇编消息: :972:错误:符号<代码>_ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037ES2_LS0 _1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_10LS0_6 4011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15LS0_64 016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0_6402 1E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_64026 E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_64031E1 3main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036E13m ain_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13mai n_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13main _null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3_L S0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm4E S_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12main_ null_4LS0_64005E12main_null_5LS0_64006E12main_null_6​​LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010E S6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_LS 0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_640 29ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY :8191:错误:符号_ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037E S2_LS0_1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_1 0LS0_64011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15L S0_64016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0 _64021E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_6 4026E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_640 31E13main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036 E13main_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13 main_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13ma in_null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3 _LS0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm 4ES_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12mai n_null_4LS0_64005E12main_null_5LS0_64006E12main_null_6​​LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010 ES6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_L S0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_64 029ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY make: * [unpack_test] 错误 1

I am having issue in compiling code having templated classes nested within other templated classes. The major templated class, called MyClass has 50 template arguments accepting a default class type called null_type_nn doing nothing specific.

My template arguments start all with the '_' character like below

     template< 
         class T0=null_type_0
       , class T1=null_type_1
       , ...
       , class T50=null_type_50
     > MyClass;

     typedef MyClass< _MyClassB, _MyClassC > _MyClass1;
     typedef MyClass< _MyClassD, _MyClassE > _MyClass2;
     .....
     typedef MyClass< _MyClass1, _MyClass2, _MyClass3 , ..._MyClass50> my_type_a;

If I don't call a certain member function of the class I don't have the error below; If I just construct a message and then access/use one of its data member I have no problem.

What I can do to sort it out or help the compiler in its job?

       : Assembler messages:
       :8851: Error: symbol `_ZN12mine_structIL10EncodingID5015ELS0_1011E11
       AsciiStringLS0_1115E23AsciiAlphaNumericStringLS0_1130ES2_LS0_1019E6S
       Int16LS0_1066ES2_LS0_5030E11mine_unionILm1ES_ILS0_5042ELS0_15ES1_
       LS0_16404E11mine_arrayILm4ES_ILS0_20ELS0_18ES2_LS0_1078ES3_LS0_2ES3_
       LS0_19E5Dec32LS0_16E6SInt32LS0_64005E12mine_null_5LS0_64006E12
       mine_null_6LS0_64007E12mine_null_7LS0_64008E12mine_null_8LS0_64009E12
       mine_null_9LS0_64010E13mine_null_10LS0_64011E13mine_null_11LS0_64012E13
       mine_n...// continues..it is a very big error!

The complete error log is the following


: Assembler messages:
:972: Error: symbol _ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037ES2_LS0_1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_10LS0_64011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15LS0_64016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0_64021E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_64026E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_64031E13main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036E13main_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13main_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13main_null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3_LS0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm4ES_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12main_null_4LS0_64005E12main_null_5LS0_64006E12main_null_6LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010ES6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_LS0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_64029ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY
:8191: Error: symbol
_ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037ES2_LS0_1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_10LS0_64011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15LS0_64016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0_64021E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_64026E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_64031E13main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036E13main_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13main_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13main_null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3_LS0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm4ES_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12main_null_4LS0_64005E12main_null_5LS0_64006E12main_null_6LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010ES6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_LS0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_64029ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY
make: * [unpack_test] Error 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮坠入山谷 2024-12-11 10:25:05

来自 C++ 2003 标准:

17.4.3.2.1 全局名称 [lib.global.names]

某些名称和函数签名集始终保留给
实施:

每个包含双下划线 (_ _) 或以
下划线后跟一个大写字母 (2.11) 保留给
任何用途的实施。

_MyClassB_MyClassC...是保留名称。

From C++ 2003 Standard:

17.4.3.2.1 Global names [lib.global.names]

Certain sets of names and function signatures are always reserved to
the implementation:

Each name that contains a double underscore (_ _) or begins with an
underscore followed by an uppercase letter (2.11) is reserved to the
implementation for any use.

_MyClassB, _MyClassC... are reserved names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文