1

I'm trying to use an initializer list in XCode 4,

struct Vector2f
{
  float x,y;
  Vector2f():x(0.f),y(0.f){}
  Vector2f( float ix, float iy ):x(ix),y(iy){}
} ;

But I'm getting 7 compiler errors,

errors

So it looks like it thinks I'm doing some "bit-field" business, but I'm trying to use an initializer list!

The code file is marked as "C++ header" in the file properties, but it seems it's compiling as C?

bobobobo
  • 64,917
  • 62
  • 258
  • 363
  • 1
    Headers are not generally compiled on their own. Their content gets compiled when it is included in another file. Are you including this C++ header in a C file? – bames53 Sep 07 '12 at 23:23
  • Included in an Objective-C (.m) file – bobobobo Sep 07 '12 at 23:29

1 Answers1

1

Oh, I see. The file that was including this C++ source was a .m file -- ie it was being compiled as "Objective-C".

Renaming the #includeing file to .mm changes it's compilation mode to Objective-C++, then the compilation of the Vector2f C++ class is successful.

  • The other error I got (when I changed struct Vector2f to class Vector2f)

Unknown type name 'class'; did you mean 'Class'?

Community
  • 1
  • 1
bobobobo
  • 64,917
  • 62
  • 258
  • 363