• <tfoot id='NwbiF'></tfoot>

    1. <i id='NwbiF'><tr id='NwbiF'><dt id='NwbiF'><q id='NwbiF'><span id='NwbiF'><b id='NwbiF'><form id='NwbiF'><ins id='NwbiF'></ins><ul id='NwbiF'></ul><sub id='NwbiF'></sub></form><legend id='NwbiF'></legend><bdo id='NwbiF'><pre id='NwbiF'><center id='NwbiF'></center></pre></bdo></b><th id='NwbiF'></th></span></q></dt></tr></i><div id='NwbiF'><tfoot id='NwbiF'></tfoot><dl id='NwbiF'><fieldset id='NwbiF'></fieldset></dl></div>
        <bdo id='NwbiF'></bdo><ul id='NwbiF'></ul>

      1. <small id='NwbiF'></small><noframes id='NwbiF'>

        <legend id='NwbiF'><style id='NwbiF'><dir id='NwbiF'><q id='NwbiF'></q></dir></style></legend>
      2. extern C 不能在类级别使用?

        时间:2023-12-03

            • <i id='HVjDk'><tr id='HVjDk'><dt id='HVjDk'><q id='HVjDk'><span id='HVjDk'><b id='HVjDk'><form id='HVjDk'><ins id='HVjDk'></ins><ul id='HVjDk'></ul><sub id='HVjDk'></sub></form><legend id='HVjDk'></legend><bdo id='HVjDk'><pre id='HVjDk'><center id='HVjDk'></center></pre></bdo></b><th id='HVjDk'></th></span></q></dt></tr></i><div id='HVjDk'><tfoot id='HVjDk'></tfoot><dl id='HVjDk'><fieldset id='HVjDk'></fieldset></dl></div>

                  <tbody id='HVjDk'></tbody>
              1. <legend id='HVjDk'><style id='HVjDk'><dir id='HVjDk'><q id='HVjDk'></q></dir></style></legend>
              2. <tfoot id='HVjDk'></tfoot>
                  <bdo id='HVjDk'></bdo><ul id='HVjDk'></ul>

                  <small id='HVjDk'></small><noframes id='HVjDk'>

                • 本文介绍了extern C 不能在类级别使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  只是想确认在Windows环境下,VSTS 2008 + C++项目中,我们只能将extern C应用到函数级别,不能应用到类级别(所以类中的所有成员函数都使用C语言名称mangling)?试了好几种方法,总是编译错误.

                  Just want to confirm in Windows environment, VSTS 2008 + C++ project, we could only apply extern C to function level, not be able to apply to class level (so that all member functions from the class use C language name mangling)? I have tried several ways, but always compile error.

                  提前致谢,乔治

                  推荐答案

                  您可以通过一种非常复杂(但完全合法)的 hack 将 extern "C" 应用于成员函数:

                  You can sort of apply extern "C" to a member function via a very convoluted (but entirely legal) hack:

                  extern "C" typedef int bar_t(int x);
                  
                  struct foo {
                       bar_t bar; // yes, this declares a nonstatic member function!
                  };
                  
                  int foo::bar(int x) { return x; } // definition
                  

                  根据 ISO C++03 9.3[class.mfct]/9,这是可能的:

                  This is possible according to ISO C++03 9.3[class.mfct]/9:

                  可以使用函数类型的 typedef 声明(但未定义)成员函数.结果成员函数的类型与显式提供函数声明符时的类型完全相同,参见 8.3.5.

                  a member function can be declared (but not defined) using a typedef for a function type. The resulting member function has exactly the same type as it would have if the function declarator were provided explicitly, see 8.3.5.

                  然而,由于 ISO C++03 7.5[dcl.link]/4,这并没有真正给你带来任何好处:

                  However, this doesn't really buy you anything, because of ISO C++03 7.5[dcl.link]/4:

                  忽略类成员和成员函数的名称的 C 语言链接类成员函数的类型.

                  A C language linkage is ignored for the names of class members and the member function type of class member functions.

                  这篇关于extern C 不能在类级别使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:错误 C2228:“.size"的左边必须有类/结构/联合 下一篇:Visual Studio 编译器警告 C4250(“class1":通过优势继承“class2::membe

                  相关文章

                  <tfoot id='5c1JB'></tfoot>
                • <small id='5c1JB'></small><noframes id='5c1JB'>

                    <i id='5c1JB'><tr id='5c1JB'><dt id='5c1JB'><q id='5c1JB'><span id='5c1JB'><b id='5c1JB'><form id='5c1JB'><ins id='5c1JB'></ins><ul id='5c1JB'></ul><sub id='5c1JB'></sub></form><legend id='5c1JB'></legend><bdo id='5c1JB'><pre id='5c1JB'><center id='5c1JB'></center></pre></bdo></b><th id='5c1JB'></th></span></q></dt></tr></i><div id='5c1JB'><tfoot id='5c1JB'></tfoot><dl id='5c1JB'><fieldset id='5c1JB'></fieldset></dl></div>
                      <bdo id='5c1JB'></bdo><ul id='5c1JB'></ul>
                    <legend id='5c1JB'><style id='5c1JB'><dir id='5c1JB'><q id='5c1JB'></q></dir></style></legend>