OGeek|极客世界-中国程序员成长平台

标题: c++ - 如何在 ios 中将函数从 .m 文件调用到 .mm 文件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:22
标题: c++ - 如何在 ios 中将函数从 .m 文件调用到 .mm 文件

我在 .mm 文件中有函数。

我想从我的 Viewcontroller 文件 .m 中调用该函数。但是当我尝试导入 c 函数的 .h 文件时,它总是给我编译器错误。

我有类似的类文件。

OpenCV.h
OpenCV.mm

ViewController 类

ViewController.h
ViewController.m

现在当我导入 OpenCV.h 时,它给了我错误。无法编译

#import "OpenCV.h"  //Error Line
@implementation ViewController
@end

那么我如何在 .m 类中使用 .mm 方法

OpenCV.h 文件中出现错误

enter image description here



Best Answer-推荐答案


你不能这样做——你试图在 Objective-C 上下文中编译一个 Objective-C++ 头文件。您应该能够将 ViewController.m 的名称更改为 ViewController.mm 以将其编译为 Objective-C++。

关于c++ - 如何在 ios 中将函数从 .m 文件调用到 .mm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24189496/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4