这是否会导致引用在超出范围后不指向任何内容
Will this cause a reference to point to nothing after it goes out of scope?
以下代码安全吗?
class B {
public:
int& b;
B (int& _b) :
b(_b) {}
};
B* foo() {
int a;
return new B(a);
}
foo返回的对象中的引用是否指向任何内容(因为int a超出了范围)还是编译解决了这个问题?
编译器可能会警告您,但新创建的对象肯定包含一个悬而未决的无效引用,因为该对象a
停止存在于foo
范围的末尾。
相关文章:
- 是否有任何内置的哈希图函数来处理 c++ 中的值输入?
- 是否有任何内置函数可以检查给定的两个数字在给定整数数组中的顺序是否相同?
- "... already defined in *.obj"但我没有在同一范围内两次定义任何变量
- C++ 中是否有任何内置阶乘函数?
- 是否有任何内置函数可以告诉编译器分支是否可预测
- 如何检查copy_if是否返回使用ostream_iterator范围内的任何内容
- 我需要在C /C#中使用图形.我可以使用任何内置的C /C#库
- 是否有任何内置类可以处理C 中的大整数值
- c ++中是否有任何内置功能可以在计划的时间运行任务
- 错误:"任何类"未在此范围内声明
- 是否有任何内置的 UTF 在 c++ 在窗口中
- 在VC++2010中执行任何内置的ARRAY函数
- 如何在log(n)时间内找到数组任何范围内的最大值
- C++:如何在不使用任何内置函数的情况下将字符串转换为整数
- main()或任何其他函数之外的Malloc(即在全局范围内)
- 是否有任何内置的CUDA函数允许CUDA内核向主机代码报告错误?
- 'make_error_code' 未在此范围内声明,并且在实例化点通过依赖于参数的查找未找到任何声明
- 我如何在常数时间(O(1))内获得字母表(1-26)中字符的数值/位置,而不使用任何内置方法或函数
- C++中的任何内置哈希方法
- c++库中的任何内置夹子方法