Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get the error "error: unknown type name 'virtual'" when trying to compile this code?

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]

like image 582
DanZimm Avatar asked Nov 18 '11 03:11

DanZimm


3 Answers

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

like image 141
DancOfDeth Avatar answered Nov 04 '22 11:11

DancOfDeth


If you're using Xcode 4, try changing the name of file "AppDelegate.m" to "AppDelegate.mm". It works for me.

like image 43
Steve Kim Avatar answered Nov 04 '22 10:11

Steve Kim


Changing the name of file "AppDelegate.m" to "AppDelegate.mm". It's correct!

like image 2
tig Avatar answered Nov 04 '22 12:11

tig