Mixing obj-c and c++

DesertPenguin
Unregistered
 
Post: #1
I am using OneSadCookie's GameShell for my app. (I am really starting to dig cocoa and objective-c).

Now I am trying to re-use several c++ classed I have built from my obj-c view class. Thus, my app will include both Objective-C and c++ code. By converting a source file to .mm, I can get an Objective-c class with c++ references to compile just fine.

This works fine for most .m files in the project. However, when I try to convert GSOpenGLView.m to GSOpenGLView.mm, I get the following error:

Checking Dependencies
CompileC build/Scuba.build/Debug/Scuba.build/Objects-normal/i386/GSOpenGLView.o /Users/bobcober/Projects/Scuba/GSOpenGLView.mm normal i386 objective-c++ com.apple.compilers.gcc.4_0
cd /Users/bobcober/Projects/Scuba
/usr/bin/gcc-4.0 -x objective-c++ -arch i386 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -g -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fzero-link -mfix-and-continue -mmacosx-version-min=10.4 -fvisibility-inlines-hidden -I/Users/bobcober/Projects/Scuba/build/Scuba.build/Debug/Scuba.build/Scuba.hmap -F/Users/bobcober/Projects/Scuba/build/Debug -I/Users/bobcober/Projects/Scuba/build/Debug/include -I/Users/bobcober/Projects/Scuba/build/Scuba.build/Debug/Scuba.build/DerivedSources -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c /Users/bobcober/Projects/Scuba/GSOpenGLView.mm -o /Users/bobcober/Projects/Scuba/build/Scuba.build/Debug/Scuba.build/Objects-normal/i386/GSOpenGLView.o
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm: In function 'objc_object* -[GSOpenGLView initWithFrame:](GSOpenGLView*, objc_selector*, NSRect)':
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:29: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:29: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:29: error: invalid conversion from 'CGOpenGLDisplayMask' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:29: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm: In function 'void -[GSOpenGLView toggleFullScreen:](GSOpenGLView*, objc_selector*, objc_object*)':
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:236: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:236: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:236: error: invalid conversion from 'CGOpenGLDisplayMask' to 'NSOpenGLPixelFormatAttribute'
/Users/bobcober/Projects/Scuba/GSOpenGLView.mm:236: error: invalid conversion from 'int' to 'NSOpenGLPixelFormatAttribute'

It all points to a single call that sets the NSOpenGLPixelFormatAttribute array.

Any ideas on how I might resolve this - I would really like to call a c++ classes method from drawRect....

Thanks for any tips/advice
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
just add casts, eg. (NSOpenGLPixelFormatAttribute)24
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
What OSC said. So you know, C++ is much more strict about type safety than C or ObjC. A lot of conversions which are safe will require explicit casting in C++ anyway, since C++ pretty much wants to make sure *you* are certain about the casting.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  problem mixing 3d with 2d render wolfra 0 1,788 Feb 24, 2010 02:14 AM
Last Post: wolfra
  Turning off mixing iPod music dsk00 0 2,579 Jun 4, 2009 10:25 PM
Last Post: dsk00
  Mixing SDL with Cocoa Taxxodium 1 2,586 Nov 22, 2003 06:28 PM
Last Post: Mars_999
  Mixing SDL & Carbon mars 2 2,896 Jul 3, 2003 07:13 AM
Last Post: aaronsullivan
  OpenGL - mixing perspective & orthographic projections mars 5 5,427 Jul 2, 2003 06:34 PM
Last Post: Iceman