Eddy
Eddy

Reputation: 3713

C++11 for xCode errors

I want to use std collections, for example std::vector in my xCode 4.5 project. Following the explanation here no type named 'shared_ptr' in namespace 'std' I changed my compiler options accordingly, but now when I come to build the project I get a bunch of errors such as Type float cannot be narrowed to GLubyte (aka unsigned char) in initializer list.

These errors are in a ccType.h, which is part of the Cocos2d library I'm using for my game.

I'm thinking the right thing to do is not to start debugging Cocos2d, but to change some of the compiler options.

How should I proceed?

Here is the code that causes the errors:

static inline ccColor4B ccc4BFromccc4F(ccColor4F c) {
    return (ccColor4B){c.r*255.f, c.g*255.f, c.b*255.f, c.a*255.f};
}

The error message is exactly as I brought it above.

Upvotes: 1

Views: 825

Answers (1)

Jack
Jack

Reputation: 133599

You should cast the type accordingly because C++11 disallow implicit conversion in initialisers lists, specifically in this case from float to unsigned char.

I guess this should be enough to solve the issue:

return (ccColor4B){static_cast<GLubyte>(c.r*255.f), static_cast<GLubyte>(c.g*255.f), static_cast<GLubyte>(c.b*255.f), static_cast<GLubyte>(c.a*255.f)};

Upvotes: 2

Related Questions