C++到 Objective-C ,在 for 循环中使用 const int
在我的头文件啊,我
const int a = 4;
的源文件 a.cpp (扩展名是 cpp,但类型是 Objective c ),我有
#import "a.h"
int func(){
for(int i = 0; i < a -1 ; i++){
}
}
但是,在编译这个时,我收到错误“找不到'a'的协议声明” ”。
为什么会发生这种情况以及如何解决这个问题?
谢谢 !
In my header file a.h, I have
const int a = 4;
in my source file a.cpp ( the extension is cpp, but the type is objective c ), i have
#import "a.h"
int func(){
for(int i = 0; i < a -1 ; i++){
}
}
However, on compiling this, I get the error "cannot find protocol declaration for 'a'".
Why is this occurring and how can I fix this ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就其本身而言,您的代码是正确的 - 不需要协议,并且如果您这样做,编译定义为
sourcecode.cpp.objcpp
的a.cpp
将会被阻塞。附带说明一下,您可以将
ah
定义为sourcecode.ch
,即使它包含纯 C++ - 这就是#includes
文件的方式> 或#imports
属于重要的类别。我见过一些递归包含/导入可能会生成这样的虚假错误的实例。
除此之外,XCode 项目可能已被破坏——您是否尝试过设置一个新的骨架项目并向其中添加这些文件?
In itself, your code is correct -- there is no need for a protocol and compiling
a.cpp
defined as asourcecode.cpp.objcpp
would choke if you did.As a side note, you can leave
a.h
defined as asourcecode.c.h
even if it contains pure C++ -- it's how the file that#includes
or#imports
is categorized that matters.I've seen some instances where recursive includes/imports can generate spurious errors like this.
Other than that, It's possible that the XCode project has gotten munged -- have you tried setting up a new skeleton project and adding these files to it?