C++11新特性(一)auto for( : )语句简单使用
来源:互联网 发布:淘宝上的古着店 编辑:程序博客网 时间:2024/05/17 18:12
cocos2dx3.2里面用到许多c++11的新特性:
参考网站:http://www.codeproject.com/Articles/570638/Ten-Cplusplus11-Features-Every-Cplusplus-Developer
#include <string>
#include <iostream>
#include <vector>
using namespace std;
#define CC_CONSTRUCTOR_ACCESS protected
class Sprite
{
public:
staticSprite* createWithPath(conststring &path);// create a sprite with path
void showSpritePath();// print the path of a sprite
CC_CONSTRUCTOR_ACCESS:
Sprite():m_strPath(""){}
bool initWithPath(conststring &path);
private:
string m_strPath;
};
Sprite*Sprite::createWithPath(conststring &path)
{
auto sprite =new Sprite();
if (sprite && sprite->initWithPath(path)) {
return sprite;
}
else
{
return nullptr;
}
}
voidSprite::showSpritePath()
{
cout <<m_strPath <<endl;
}
boolSprite::initWithPath(conststring &path)
{
m_strPath = path;
return true;
}
int main()
{
int students[]{1,2,4, 5, 4,6};
for (auto s : students)
{
cout << s <<endl;
}
vector<Sprite*> vcSprites;
auto s = Sprite::createWithPath("fish.png");
vcSprites.push_back(s);
auto s2 = Sprite::createWithPath("cat.png");
vcSprites.push_back(s2);
for (auto s : vcSprites) {
s->showSpritePath();
}
for (auto s : vcSprites) {
delete s;
}
vcSprites.clear();
return 0;
}
好了就这样,很简单。顺便问下,最近学习xcode工具,编写c++,有点不方便不如vs,xcode对于c++的自动完成功能不太给力,
有木有xcode支持c++编写的插件,求介绍几款。谢谢
- C++11新特性(一)auto for( : )语句简单使用
- c++11新特性 auto的使用
- c++11新特性--auto的使用
- MSSQL XML使用(一):由简单的select语句Auto 生产XML
- 【C++11】新特性——auto的使用 (@huang_xw)
- C#: VS2008的新特性(一)
- c++11新特性--auto
- Eclipse for C/C++(一)简介和简单使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性 之 auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- 【C++11】新特性——auto的使用
- Uva 1585 Score
- 猜字游戏 算法
- Unity屏幕震动效果
- 2014年中科院地理所博士考试真题遥感概论
- MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法
- C++11新特性(一)auto for( : )语句简单使用
- 什么是网络新闻软文营销?
- USB IP bug
- 类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们的问题的解决方法
- Spring中的定时器
- 你的心,决定你看见的
- jquery AJAX提交表单程序php
- JS中:关于form中的Checkbox的操作: document.getElementsByName("name"),如何取消选中状态,如何将文本框内容清空
- bzoj1059: [ZJOI2007]矩阵游戏 二分图