为什么我在这个模板上有随机结果?
Why do i have a random result on this template?
有人可以告诉我为什么我有随机结果吗?
template<class T, class U>
T f(T x, U y)
{
return x+y;
}
int f(int x, int y)
{
return x-y;
}
int main()
{
int *a=new int(3), b(23);
cout<<*f(a,b);
return 0;
}
b(23( 是什么意思?非常感谢!
实例化的模板将是
int* f(int* x, int y)
{
return x + y;
}
因此,您将执行指针算术,然后取消引用未在其中分配的指针,该指针恰好在a
之后递增 23 个地址。
这基本上就像你打电话给
*(new int(23) + 23);
相关文章:
- C++剪贴板队列粘贴随机结果?
- 为什么我在这个模板上有随机结果?
- 我在运行函数 GetVolumeInformation() 时得到非常随机的结果
- 如果我在每个平台上使用相同的种子,随机结果会相同吗?
- 尝试以随机字符(长读取)打印字符串返回结果
- C 编程:在循环时运行 2 并从 loop1 获取数据的随机结果
- 随机洗牌似乎会产生相同的结果,但仅在前两个实例中产生相同的结果.我如何避免这种情况
- 我如何在 c++ 中执行随机结果,如下所示的代码
- C++时间()给我的结果几乎是随机的
- 生成随机骰子并测量结果的频率
- 生成随机QString每次都会产生相同的结果
- 简单的代码,看似随机的结果——这是由于过时的引用造成的吗
- C++随机字符串返回意外结果
- 为什么起始值会影响种子随机的结果
- 如何使用 std::mt19937 避免相同的随机结果
- 当我编译和运行C++时,随机生成器给出了相同的结果
- 使用pthread时的随机结果
- 如何创建一个不会重复结果的随机事件
- 为什么rand()/double(rand_MAX)的第一个结果不是随机的
- 为什么我得到随机结果与移位操作符(c++)