关于C++ string::size_type的问题
因为用来改优先级的括号只能括表达式。这是个声明:string::size_type pos = input.find(",")这是个表达式:pos = input.find(",")
■网友
跟size_type没关系,你写 while ( (int x = foo()) != -1) 一样编译不过。
■网友
一、Primary expressions 定义The operands of any operator may be other expressions or primary expressions (e.g. in 1+2*3, the operands of operator+ are the subexpression 2*3 and the primary expression 1).
Primary expressions are any of the following:
1) Literals (e.g. 2 or "Hello, world")2) Suitably declared unqualified identifiers (e.g. n or cout)3) Suitably declared qualified identifiers (e.g. std::string::npos)4) Lambda-expressionsAny expression in parentheses is also classified as a primary expression: this guarantees that the parentheses have higher precedence than any operator.
二、测试
1、if里有变量声明
if ( string::size_type pos = input.find ( "," ) ) {
//可行
}
2、多一对括号
if ( ( string::size_type pos = input.find(",") ) ) {
//error: expected primary-expression before \u0026#39;pos\u0026#39;
}
三、结论
Any expression in parentheses is also classified as a primary expression
【关于C++ string::size_type的问题】 括号表达式需要是基本表达式(primary expression),分类包含上面一中的1)—4),可看出不包括变量声明语句。
■网友
因为定义变量不是表达式,所以不能做子表达式
推荐阅读
- 过节■江苏省委省政府办公厅下发关于做好2021年元旦春节期间有关工作的通知
- |徐州市出台《关于优化创新创业生态系统 提升区域科技创新活力的实施意见》及实施细则
- 雨下|全球关于禁售燃油车只是理论上可行吗
- 关于用phpfsocket 写Post, 模拟http 报文怎样写入要传输的处理数据
- 智叔|很多家长还在整箱买:谈谈关于牛奶的17个真相警惕这些列入黑名单的“假牛奶”
- 非计算机专业想要利用课余时间深入自学C++,想要找到比较体面的工作大概需要啥水平
- 关于微信小程序的思考:运营者该何去何从
- 关于人工智能虚拟人的一些问题
- 知乎上关于人生经验的介绍是否可能对青少年造成潜在危害
- Java工程师和C++工程师在工作上有啥区别哪个更适合自身发展
