xCode 4.2中的未知类型名称'namespace'?

Rap*_*tor 12 objective-c xcode4.2 vuforia

我正在编译QCAR SDK,但是在我向项目中添加了更多框架后会出现错误.

// Matrices.h
//
#ifndef _QCAR_MATRIX_H_
#define _QCAR_MATRIX_H_

namespace QCAR
{

/// Matrix with 3 rows and 4 columns of float items
struct Matrix34F {
    float data[3*4];   ///< Array of matrix items
};


/// Matrix with 4 rows and 4 columns of float items
struct Matrix44F {
    float data[4*4];   ///< Array of matrix items
};

} // namespace QCAR

#endif //_QCAR_MATRIX_H_
Run Code Online (Sandbox Code Playgroud)

在线namespace QCAR,它说Unknown type name 'namespace'.

我该怎么办 ?

更新:这是构建脚本

In file included from ../../build/include/QCAR/Tool.h:18:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:14:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/ImageTargetsAppDelegate.h:9:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/CouponBook.m:12:
../../build/include/QCAR/Matrices.h:16:1: error: unknown type name 'namespace' [1]
 namespace QCAR
 ^
../../build/include/QCAR/Matrices.h:16:15: error: expected ';' after top level declarator [1]
 namespace QCAR
               ^
               ;
fix-it:"../../build/include/QCAR/Matrices.h":{16:15-16:15}:";"
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/ImageTargetsAppDelegate.h:9:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/CouponBook.m:12:
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:5: error: type name requires a specifier or qualifier [1]
     QCAR::Matrix44F projectionMatrix;
     ^
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:10: error: expected expression [1]
     QCAR::Matrix44F projectionMatrix;
          ^
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:5:{52:5-52:9}: warning: type specifier missing, defaults to 'int' [-Wimplicit-int,3]
     QCAR::Matrix44F projectionMatrix;
     ^~~~
1 warning and 4 errors generated.
Run Code Online (Sandbox Code Playgroud)

Rin*_*cha 18

您可以使用.mm重命名文件,也可以选择.m文件并将"文件类型"更改为"Objective-C++ Source".

文件类型


jus*_*tin 17

我怀疑翻译是C或Objective-C,namespace它不是C++和Objective-C++中的关键字.

另一种可能性是前一个标题没有关闭一个主体(例如};,}在函数定义结束时忘记了类遗忘的结尾).

  • @Shivan你正在编译的文件是一个`.m`文件,用于objc.从成绩单的开头就缺少命令调用,所以我不能肯定地说编译器已被告知将文件编译为objc ++.所以,试试这个:改变扩展名,从`CouponBook.m`改为`CouponBook.mm`.使用`.mm`,文件将被编译为objc ++,除非您已在其他地方明确禁用该行为.为了使编译器能够在同一个转换中识别c ++和objc程序,您需要编译为objc ++. (9认同)
  • 正确.在我重命名为`.mm`后,问题就消失了.谢谢你的帮助! (4认同)