本文介绍了为什么我会收到错误“错误:未知类型名称'virtual'"在尝试编译此代码时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

  struct IRenderingEngine {
virtual void Initialize(int width,int height)= 0;
virtual void Render()const = 0;
virtual void UpdateAnimation(float timeStep)= 0;
virtual void OnRotate(DeviceOrientation newOrientation)= 0;
virtual~IRenderingEngine(){}
};

从一本书中学习用于3d iphone编程的opengles它使用这个示例代码,但本书的目标是xcode 3.x



不知何故,我觉得它与xcode 4有关....



编辑:



下面是实际错误:



/ Users / Dan / Documents / opengles / Hello Arrow / Hello Arrow / IRenderingEngine .hpp:27:2:错误:未知类型名称'virtual'[1]



而且合法的是编译失败所需的全部内容,绝对没有其他文件。 (是的,我尝试使用字面上的main.m和这个hpp文件进行编译)



虽然我正在尝试将hpp文件识别为cpp头文件将它添加到已编译的文件中它表示没有规则处理文件'$(PROJECT_DIR)/ Hello Arrow / IRenderingEngine.hpp'类型为sourcecode.cpp.h,用于体系结构i386所以我真的不知道发生了什么/ p>

请注意,我使用main.m编译意味着我编译了另一个基于Cocoa / Foundation的应用程序



我尝试编译为一个c ++应用程序,一切都很好....
同样使用main.mm测试文件编译工作也很好



继承人的实际项目,lemme知道我到底有多疯狂:



[删除考虑我丢失了文件]

解决方案

请将main.m重命名为main.mm.这对我有用。


Code:

struct IRenderingEngine {
    virtual void Initialize(int width, int height) = 0;
    virtual void Render() const = 0;
    virtual void UpdateAnimation(float timeStep) = 0;
    virtual void OnRotate(DeviceOrientation newOrientation) = 0;
    virtual ~IRenderingEngine() {}
};

Learning opengles from a book for 3d iphone programming and it uses this example code but the book is targeted for xcode 3.x

Somehow I feel like its something with xcode 4....

EDIT:

Heres the actual error:

/Users/Dan/Documents/opengles/Hello Arrow/Hello Arrow/IRenderingEngine.hpp:27:2: error: unknown type name 'virtual' [1]

And that legitamtely is all that it takes to fail to compile, absolutely no other files. (Yes I've tried compiling with literally a main.m and this hpp file)

It is recognizing the hpp file as a cpp header file though, if I try to add it to the compiled files it says that "no rule to process file '$(PROJECT_DIR)/Hello Arrow/IRenderingEngine.hpp' of type sourcecode.cpp.h for architecture i386" so I really have no idea what is going on

Note that I compiled with main.m meaning I compiled another Cocoa/Foundation based application

I tried compiling for a c++ application and everything worked out just fine....Similarly compiling with a main.mm test file worked fine too

heres the actual project, lemme know how insane I really am:

[Removed considering I lost the file]

解决方案

Please rename the main.m to main.mm. This worked for me.

这篇关于为什么我会收到错误“错误:未知类型名称'virtual'"在尝试编译此代码时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 06:57