• <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 不能在类级别使用?

        extern C can not be used at class level?(extern C 不能在类级别使用?)

            • <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 不能在类级别使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)
                  <tfoot id='5c1JB'></tfoot>
                  • <small id='5c1JB'></small><noframes id='5c1JB'>

                        <tbody id='5c1JB'></tbody>

                        <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>