在c ++程序中调用函数,其中函数在其他c ++程序中声明 [英] calling function in c++ program where function is declared in other c++ program

查看:70
本文介绍了在c ++程序中调用函数,其中函数在其他c ++程序中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c ++程序中调用函数,其中函数在其他 c ++程序中声明?
怎么能这样做?可以使用 extern

how can one called function in c++ program where function is declared in other c++ program? how can one do this? can i use extern?

推荐答案

我建议最好的方法是重构第一个C ++程序使得所需的功能成为的一部分。然后你的程序都可以链接到该库,并且函数可用于两者(以及任何其他需要它的程序)。

I would suggest the best way is to refactor the first C++ program such that the required function is made part of a library. Then both your programs can link to that library and the function is available to both (and to any other programs requiring it).

查看本教程。它包括如何使用 gcc 创建并使用库。其他类似的教程将存在其他C ++变体。

Take a look at this tutorial. It covers how to create and then use a library using gcc. Other similar tutorials will exist for other C++ variants.

这篇关于在c ++程序中调用函数,其中函数在其他c ++程序中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆