简体   繁体   中英

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.

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)};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM