mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 04:48:32 +00:00
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.
18 lines
438 B
Plaintext
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;
|
|
}
|