Question

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?

Was it helpful?

Solution

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'?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top