从C到C ++的代码重用 [英] Reusing of code from c to C++

查看:57
本文介绍了从C到C ++的代码重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我有一个C项目,我想在MFC应用程序中使用其代码(通过复制.c&.h).所以任何人都可以告诉我将.c&.h文件放在哪里或我需要任何其他文件以进行复制或如何以任何其他方式使用代码.

很抱歉使用不当的英语.在此先感谢...

Actually i am having a C project,whose code i want to use(by making copy of .c&.h) inside a MFC application.So can any one tell me where to put the .c&.h files or i need any more file to make copy or how to use the code in any other way.

Sorry for inappropriate english..and thanks in advance...

推荐答案

您可以在项目中自由地混合使用C和C ++文件.将C头文件放置在放置其他头文件的位置,并将C文件放置在放置C ++文件的位置,或创建单独的目录.

无论如何,这一切都是通过#include控制的(遗憾的是……我真不敢相信,这是XXI世纪的一种古老技术!),因此只需注意适当的include路径,并确保将C和C ++添加到项目中,生成文件并等等-进一步的细节取决于您的平台,C/C ++开发系统和环境.

—SA
You can freely mix C and C++ files in the project. Place C header files where you place other header files, and place C files where you place your C++ files, or create separate directories.

It all is controlled through #include (sigh… I cannot believe it, such an archaic technique in XXI century!) anyway, so just take care of proper include paths and makes sure C and C++ are added to the project, make file and the like — further detail depend on your platform, C/C++ development system and environment.

—SA


您可以将它们直接添加到MFC解决方案中,并使用必要的C函数.

假设您在C1.h中具有Function_1(),在C1.c中具有其定义,并且如果要在MyView.cpp(MFC应用程序中的cpp)中使用它,
1.然后将C1.h和C1.c添加到您的MFC解决方案中,并且
2.在MyView.cpp和
中#include C1.h 3.在必要的MyView成员函数中使用Function_1()

希望我对你清楚!!!
You can directly add them to your MFC solution and use the necessary C functions.

Say suppose you are having Function_1() in C1.h and its definition in C1.c and if you want to use this in MyView.cpp (a cpp in your MFC app)
1. then add C1.h and C1.c to your MFC solution and
2. #include C1.h in MyView.cpp and
3. use Function_1() in necessary MyView member function

Hope I am clear to you!!!



  1. 将库项目添加到您的解决方案中
  2. 将文件包含到该项目中
  3. 全部编译
  4. 访问代码中的h个文件
  5. 编译并链接所有

  1. add a library project to your solution
  2. include the files to that project
  3. compile all
  4. access the h files in your code
  5. compile and link all


这篇关于从C到C ++的代码重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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