代码之家  ›  专栏  ›  技术社区  ›  domlao

从C源代码调用C++函数

c c++
  •  1
  • domlao  · 技术社区  · 16 年前

    从C源代码调用C++函数是可能的吗?

    请教。

    多谢。

    5 回复  |  直到 16 年前
        1
  •  9
  •   wkl    16 年前

    extern C construct

     // This is C++ code
    
     // Declare f(int,char,float) using extern "C":
     extern "C" void f(int i, char c, float x);
    
     ...
    
     // Define f(int,char,float) in some C++ module:
     void f(int i, char c, float x)
     {
       ...
     }
    

    extern "C"
    {
       void func1();
       void func2();
    }
    
    extern "C"
    {
       void func1()
       {
          /// do something
       }
    
       void func2()
       {
          // do something else
       }
    }
    

    #include extern "C"

       extern "C"
       {
          #include "myHeader.h"
       }
    

    myHeader.h

        2
  •  3
  •   justin    16 年前

        3
  •  2
  •   Jack Kelly    16 年前
        4
  •  2
  •   jrockway    16 年前

    http://github.com/jrockway/cplusplus-binding-examples

    std::string char *

    foo foo_4dskjaf3874hdfas extern "C"

        5
  •  0
  •   Community Mohan Dere    9 年前

    #include extern "C"

    this