包含了一个initializer_list头文件,为什么向它的形参传递一个值的序列,把这个序列放在花括号中编译器显示说不对 附:编译器是VS2012

tiffinysmile tiffinysmile 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
initializer_list 头文件
#pragma once
#ifndef _INITIALIZER_LIST_
#define _INITIALIZER_LIST_
#ifndef RC_INVOKED
#include <cstddef>

#pragma pack(push,_CRT_PACKING)
#pragma warning(push,3)
#pragma push_macro("new")
#undef new

_STD_BEGIN
// TEMPLATE CLASS initializer_list
template<class _Elem>
class initializer_list
{ // list of pointers to elements
public:
typedef _Elem value_type;
typedef const _Elem& reference;
typedef const _Elem& const_reference;
typedef size_t size_type;

typedef const _Elem* iterator;
typedef const _Elem* const_iterator;

initializer_list() _NOEXCEPT
: _First(0), _Last(0)
{ // empty list
}

initializer_list(const _Elem *_First_arg,
const _Elem *_Last_arg) _NOEXCEPT
: _First(_First_arg), _Last(_Last_arg)
{ // construct with pointers
}

const _Elem *begin() const _NOEXCEPT
{ // get beginning of list
return (_First);
}

const _Elem *end() const _NOEXCEPT
{ // get end of list
return (_Last);
}

size_t size() const _NOEXCEPT
{ // get length of list
return ((size_t)(_Last - _First));
}

private:
const _Elem *_First;
const _Elem *_Last;
};

// TEMPLATE FUNCTION begin
template<class _Elem> inline
const _Elem *begin(initializer_list<_Elem> _Ilist) _NOEXCEPT
{ // get beginning of sequence
return (_Ilist.begin());
}

// TEMPLATE FUNCTION end
template<class _Elem> inline
const _Elem *end(initializer_list<_Elem> _Ilist) _NOEXCEPT
{ // get end of sequence
return (_Ilist.end());
}
_STD_END

#pragma pop_macro("new")
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _INITIALIZER_LIST_ */

编写一个主函数

#include<iostream>
#include"initializer_list.h"
using namespace std;
void add(initializer_list<int> a)
{
int sum =0;
for(auto beg = a.begin(),end = a.end();beg != end;beg++)
{

sum+=*beg;
}
cout << sum <<endl;

}
void main()
{

add ({2,1,0});



}
...全文

相关推荐

Google C++ Style Guide

This style guide contains many details that are initially hidden from view. They are marked by the triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear below.

hasee726

google c++代码规范

Google C++ 编程规范 目录 一、头文件........................................................................................................................................4 1. #define的保护....................................................................................................................... 4 2. 头文件依赖.......................................................................................................................... 4 3. 内联函数.............................................................................................................................. 5 4. -inl.h文件.......................................................................................................................... 5 5. 函数参数顺序(Function Parameter Ordering)............................................5 6. 包含文件的名称及次序......................................................................................................6 二、作用域........................................................................................................................................7 1. 命名空间(Namespaces)..........................................................................................7 2. 嵌套类(Nested Class)............................................................................................. 9 3. 非成员函数(Nonmember)、静态成员函数(Static Member)和全局函 数(Global Functions)...................................................................................................9 4. 局部变量(Local Variables)..................................................................................10 5. 全局变量(Global Variables)............................................................................... 10 三、类..............................................................................................................................................11 1. 构造函数(Constructor)的职责..............................................................................11 2. 默认构造函数(Default Constructors)............................................................. 12 3. 明确的构造函数(Explicit Constructors).........................................................12 4. 拷贝构造函数(Copy Constructors)...................................................................13 5. 结构体和类(Structs vs. Classes)......................................................................14 6. 继承(Inheritance)..................................................................................................14 7. 多重继承(Multiple Inheritance)...................................................................... 15 8. 接口(Interface)....................................................................................................... 15 9. 操作符重载(Operator Overloading)...............................................................16 10. 存取控制(Access Control)................................................................................16 11. 声明次序(Declaration Order).........................................................................17 12. 编写短小函数(Write Short Functions)........................................................17 四、Google特有的风情................................................................................................................. 18 1. 智能指针(Smart Pointers).................................................................................. 18 五、其他C++特性..........................................................................................................................19 1. 引用参数(Reference Arguments)...................................................................19 2. 函数重载(Function Overloading)....................................................................19 3. 缺省参数(Default Arguments)......................................................................... 20 4. 变长数组和alloca(Variable-Length Arrays and alloca())................ 20 5. 友元(Friends)............................................................................................................20 6. 异常(Exceptions)....................................................................................................20 7. 运行时类型识别(Run-Time Type Information, RTTI)........................... 22 8. 类型转换(Casting)................................................................................................... 22 9. 流(Streams)..............................................................................................................23 10. 前置自增和自减(Preincrement and Predecrement)............................24 11. const的使用(Use of const).............................................................................24 12. 整型(Integer Types)..........................................................................................25 13. 64位下的可移植性(64-bit Portability)........................................................ 26 14. 预处理宏(Preprocessor Macros)..................................................................27 15. 0和NULL(0 and NULL)....................................................................................27 16. sizeof(sizeof)........................................................................................................28 17. Boost库(Boost)................................................................................................... 28 六、命名约定..................................................................................................................................29 1. 通用命名规则(General Naming Rules)..........................................................29 2. 文件命名(File Names)........................................................................................... 30 3. 类型命名(Type Names).........................................................................................31 4. 变量命名(Variable Names).................................................................................31 5. 常量命名(Constant Names)............................................................................... 31 6. 函数命名(Function Names)................................................................................32 7. 命名空间(Namespace Names)......................................................................... 32 8. 枚举命名(Enumerator Names).........................................................................32 9. 宏命名(Macro Names)..........................................................................................33 10. 命名规则例外(Exceptions to Naming Rules)..........................................33 七、注释..........................................................................................................................................34 1. 注释风格(Comment Style)..................................................................................34 2. 文件注释(File Comments)...................................................................................34 3. 类注释(Class Comments)...................................................................................34 4. 函数注释(Function Comments)....................................................................... 35 5. 变量注释(Variable Comments)........................................................................36 6. 实现注释(Implementation Comments)...................................................... 37 7. 标点、拼写和语法(Punctuation, Spelling and Grammar)................... 38 8. TODO注释(TODO Comments).........................................................................38 八、格式..........................................................................................................................................39 1. 行长度(Line Length)..............................................................................................39 2. 非ASCII字符(Non-ASCII Characters)..........................................................40 3. 空格还是制表位(Spaces vs. Tabs).................................................................... 40 4. 函数声明与定义(Function Declarations and Definitions)...................40 5. 函数调用(Function Calls).................................................................................... 42 6. 条件语句(Conditionals)........................................................................................43 7. 循环和开关选择语句(Loops and Switch Statements).............................44 8. 指针和引用表达式(Pointers and Reference Expressions)...................45 9. 布尔表达式(Boolean Expressions)................................................................. 46 10. 函数返回值(Return Values)............................................................................. 46 11. 变量及数组初始化(Variable and Array Initialization)........................ 46 12. 预处理指令(Preprocessor Directives)....................................................... 46 13. 类格式(Class Format)........................................................................................47 14. 初始化列表(Initializer Lists)...........................................................................48

meditator_bi

Google C++ 编程规范(精心制作的链接文档-方便查看学习)

李开复推荐:“分享给程序员。 刚刚才发现Google的C++编码规范原来已经公开了,那就说两句,我认为这是地球上最好的一份C++编程规范,没有之一,建议广大国内外IT研究使用。”

bafghgle

libtensorflow.rar

include和tensorflow.dll、tensorflow.lib可以直接在window是环境下vs2015中调用

goodman_liqifei

Google C++ Style Guide(谷歌C++编码规范 )

谷歌C++编码规范。 C++ is the main development language used by many of Google's open-source projects. As every C++ programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain

黑桃_杰克
评论 7
收藏 已收藏
分享
返回顶部
tiffinysmile
新手乐园 33,315 成员 41,769 内容