作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个已知的特殊情况,如果将常量引用分配为常量引用,则常量引用不会在返回值中丢失:
int MyFunction()
{
int x = 5;
return x;
}
int main()
{
const int& y = MyFunction();
std::cout << "This is valid: " << std::endl;
return 0;
}
现在如果我有如下两个函数:
int MyFunction()
{
int x = 5;
return x;
}
void MyOtherFunction(const int& val)
{
std::cout << val << std::endl;
}
int main()
{
MyOtherFunction(MyFunction());
}
这是否符合标准?传递 const 引用有哪些限制?
最佳答案
是的。
[C++14: 12.2/5]:
[..] A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full-expression containing the call. [..]
关于c++ - 传递常量引用...它是否像最重要的常量一样工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31406495/
Haskell 是一种具有许多 Root 于形式数学的特征的语言。我应该学习哪些数学主题才能更深入地了解和理解这门语言?例如,我认为抽象代数和范畴论都是值得探索的好话题。 最佳答案 一般来说,离散数学
大多数创建位图上下文的代码使用 kCGImageAlphaPremultipliedFirst 来创建 ARGB,而不是使用 kCGImageAlphaPremultipliedLast 来创建 RG
我是一名优秀的程序员,十分优秀!