mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 15:56:01 +01:00
Focus: Calling static C++ function defined in C++ classes. Limitations: * Ignores visibility (public / protected / private). * No support for: dynamic classes, member methods, data members, declarations without definitions, importing inheritance. Based on #5142. C++ Interop Demo with a class: ```c++ // hello_world.h namespace some_namespace { class MyClass { public: static void hello_world(); }; } // namespace some_namespace ``` ```c++ // hello_world.cpp #include "hello_world.h" #include <cstdio> namespace some_namespace { void MyClass::hello_world() { printf("Hello World!\n"); } } // namespace some_namespace ``` ```carbon // main.carbon library "Main"; import Cpp library "hello_world.h"; fn Run() -> i32 { Cpp.some_namespace.MyClass.hello_world(); return 0; } ``` ```shell $ clang -c hello_world.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_world.o main.o --output=demo $ ./demo Hello World! ``` Part of #5150.