11

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]

9
  • 2
    Post an SSCCE. I can't help you with this code, it's obviously not the actual source of the problem.
    – Puppy
    Nov 18 '11 at 3:13
  • pastie.org/private/07cebz0irqp6ehybicctw is literally the entire file and it will not compile. just throws the error: unknown type name 'virtual' [1]
    – DanZimm
    Nov 18 '11 at 3:17
  • What do you mean a main.m? C++ does not use .m files. Use a .cpp
    – Adam
    Nov 18 '11 at 3:35
  • I compiled a cocoa application which uses .m files
    – DanZimm
    Nov 18 '11 at 3:36
  • It's not Objective-C++ unless you use .mm
    – Hot Licks
    Nov 18 '11 at 3:42
23

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

2
  • 5
    I had to rename both main.m and AppDelegate.m with the .mm extension.
    – jessecurry
    Jan 8 '12 at 16:24
  • To get this example working in xcode 4 I also had to get delete the MainStoryboard_iPhone.storyboard and MainStoryboard_iPad.storyboard files as well as remove their references from HelloArrow-Info.plist, but the errors for those were much clearer.
    – Lockyer
    Feb 2 '12 at 1:43
2

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

2

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

2

I moved the #import "IRenderingEngine.hpp" line from the GLView.h file to the GLView.mm - this prevented it from being imported into the main.m and HelloArrowAppDelegate.m files when they were compiled - and restricted the import into the .mm file, that could handle the C++.

I also had to make a couple of other fixes for bugs I'd introduced when typing in the code - so apologies if that wasn't the only thing that needed to be done, but it might help those with similar problems!

1
  • This worked for me! Very simple solution, just move all of your instance variables into the @implementation.
    – John
    Feb 9 '13 at 5:46
1

if you call C++ files ( even if you only import them ) you need to change the .m file that call's it to .mm

0

This is just a stupid guess since I've never tried compiling something with the word virtual in a C compiler... but is there any chance that you were trying to compile this C++ code as C code? That's the only reason I can think of that a compiler wouldn't understand the keyword virtual.

1
  • supposedly xcode is compiling the files based on their file types (which this one happens to be hpp so I'm guessing it's smart enough to know that that means it's cpp)
    – DanZimm
    Nov 18 '11 at 3:20
0

The header <stdlib.h> is not the right one to use in a C++ program. When I replaced it with the c++ version of C's stdio library <cstdlib> then your code compiled for me.

1
  • when I try adding that to the header it errors that it can't find that file
    – DanZimm
    Nov 18 '11 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.