Skip to content

Add example: calling overloaded C++ function (int and const char) from Rust#27

Open
yrevash9182 wants to merge 11 commits intorustfoundation:mainfrom
yrevash9182:main
Open

Add example: calling overloaded C++ function (int and const char) from Rust#27
yrevash9182 wants to merge 11 commits intorustfoundation:mainfrom
yrevash9182:main

Conversation

@yrevash9182
Copy link
Copy Markdown

A small example showing how to call an overloaded C++ function from Rust using extern "C" wrapper functions. The C++ side has two overloads of greet() — one taking int and one taking const char*. Since Rust doesn't support function overloading, each overload is wrapped with a unique name (greet_number, greet_name) using extern "C", and called from Rust via FFI. Built using the cc crate with a build.rs script.
@teor2345

@yrevash9182
Copy link
Copy Markdown
Author

Hi @teor2345, I've updated my PR moved everything into an overloaded-greet subdirectory to match the new examples structure, added a test, and fixed the clippy/rustfmt warnings. Let me know if anything else needs changing!

Copy link
Copy Markdown
Collaborator

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, just checking some of the types match

@yrevash9182 yrevash9182 requested a review from teor2345 March 26, 2026 18:02
@teor2345 teor2345 added the p-overloading Overloading problems or examples label Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to merge after we fix up the documentation.


# Examples

## Calling Overloaded C++ from Rust
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this file readable for people adding new examples, so I don't want to add anything here yet. Adding lots of text to the same file in different PRs can also cause merge conflicts.

Please move this to the README file in the example directory, or delete it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teor2345 . Done I removed from readme

@yrevash9182
Copy link
Copy Markdown
Author

@teor2345 I have reverted the .gitignore change and moved the overloading description out of the shared README into examples/overloaded-greet/README.md

Copy link
Copy Markdown
Collaborator

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I still see an extra blank line in examples/README.md, and a deleted blank line in .gitignore.

You can reset the files to their original contents using these git commands:

git checkout main examples/README.md .gitignore
git commit

@yrevash9182 yrevash9182 requested a review from teor2345 April 8, 2026 05:48
@yrevash9182
Copy link
Copy Markdown
Author

@teor2345 i have restored .gitignore and readme for match the upstream

@yrevash9182
Copy link
Copy Markdown
Author

Hey @teor2345 , as we’re approaching the final days of Outreachy, I wanted to follow up regarding my contribution. Since this needs to be merged to be counted, I’ve completed all the requested changes.

Could you please take a look and let me know if we can move forward with merging this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p-overloading Overloading problems or examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants