C ++ 11 for xCode错误 [英] C++11 for xCode errors

查看:456
本文介绍了C ++ 11 for xCode错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的xCode 4.5项目中使用std集合,例如 std :: vector 。按照此处的说明,在命名空间std中没有名为shared_ptr的类型我改变了我的编译器选项相应,但现在当我来构建项目,我得到一堆错误,如类型float不能缩小到初始化列表中的GLubyte(aka unsigned char) code>。



这些错误是在ccType.h中,这是我用于我的游戏的Cocos2d库的一部分。



我认为正确的事情是不是开始调试Cocos2d,而是改变一些编译器选项。



我应该如何处理?



以下是导致错误的代码:



> static inline ccColor4B ccc4BFromccc4F(ccColor4F c){
return(ccColor4B){cr * 255.f,cg * 255.f,cb * 255.f,ca * 255.f};
}

错误消息正是我带来的。

解决方案

您应该相应地转换类型,因为C ++ 11不允许初始化列表中的隐式转换, c $ c> float unsigned char



以解决问题:

  return(ccColor4B){static_cast< GLubyte>(cr * 255.f),static_cast< GLubyte& (cg * 255.f),static_cast< GLubyte>(cb * 255.f),static_cast< GLubyte>(ca * 255.f)}; 


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

这篇关于C ++ 11 for xCode错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆