Files
Geoff Romer 976692abf4 Add support for C++ pointers to Carbon methods (#7881)
C++ pointers to Carbon methods are supported using the same mechanisms
as for Carbon functions: we export the method to C++ and then form a
pointer to the exported method. This change does not support invoking a
C++ method pointer from Carbon, which will be more complicated because
we need to model instance binding on the Carbon side.
2026-10-02 16:41:55 +00:00

18 lines
438 B
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import Cpp library "<functional>";
class C {
fn F(unused self: Self, i: i32) -> i32 {
return i + 1;
}
}
fn Run() -> i32 {
var c: C = {};
var n: i32 = Cpp.std.invoke(Cpp.std.bind(C.F, ref c, 1));
return if n == 2 then 0 else 1;
}