[英]Xcode: C++ error: unknown type name 'class' did you mean 'Class'
我正在嘗試在Xcode項目中實現C ++類,但出現以下錯誤:
Expected ';' after top level declarator
Unknown type name 'class'; did you mean 'Class'
#ifndef DoingSomething_hpp
#define DoingSomething_hpp
#include <stdio.h>
class DoingSomething {
public:
static DoingSomething *instance();
int doSomething();
};
#endif /* DoingSomething_hpp */
但是,在將DoingSomething.hpp添加到viewController之后,錯誤開始顯示:
#import "ViewController.h"
#import "DoingSomething.hpp"
@interface ViewController ()
你們誰都知道為什么會發生此錯誤,或者我該如何解決或是否有解決方法?
非常感謝您的幫助。
問題是您在Objective-C文件(C的超集)中使用C ++頭,這就是為什么它不識別C ++語法的原因。 為了使其正確編譯,您應該僅在c ++或Objective-C ++(.mm)源文件中包括C ++頭文件。 嘗試將viewControllers文件擴展名從.m更改為.mm
將文件擴展名從.m
(Objective C)更改為.mm
(Objective C ++),您的編譯將更加流暢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.