C++11 for xCode errors

点点圈 提交于 2019-12-11 10:52:24

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/16698090/c11-for-xcode-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!