由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 什么情况下pass by reference比pass by pointer好?
相关主题
一个简单的java题有没有人同觉得Recover Binary Search Tree的solution using O(n) space并不是那么straight forward么?
问个简单的C++ 函数参数问题我最喜欢问的问题,怎样检查out of memory
One question about Void pointer (转载)也来一道c++的题
c++ new的一个问题问一个精华区里的题目
报个电面的面经和据信吧, 求安慰merge两个有序数组
copy link with random additional pointers二维数组参数怎么传好?
reverse random pointers of a single linked list最新某公司onsite面试题
请教下copy list with random pointer谁给改一个线程安全的smarter pointer类
相关话题的讨论汇总
话题: pass话题: pointer话题: reference话题: int话题: void
进入JobHunting版参与讨论
1 (共1页)
g********l
发帖数: 68
1
谢谢
o**********t
发帖数: 406
2
you cannot allocate a new block of RAM in sub function if you pass pointer.
s*****r
发帖数: 773
3
如果明确知道可以不为空,就用pass by refernece, 这样就不用每次都check 指针置
否为空了
void f( int* i) {
if(i == NULL) {
}
}
void f(int&i) {
//use i directly here.
}

【在 g********l 的大作中提到】
: 谢谢
w****m
发帖数: 146
4
second this

【在 s*****r 的大作中提到】
: 如果明确知道可以不为空,就用pass by refernece, 这样就不用每次都check 指针置
: 否为空了
: void f( int* i) {
: if(i == NULL) {
: }
: }
: void f(int&i) {
: //use i directly here.
: }

s*****r
发帖数: 773
5
啥意思?

【在 w****m 的大作中提到】
: second this
f*******e
发帖数: 1161
6
second=support

【在 s*****r 的大作中提到】
: 啥意思?
l******c
发帖数: 2555
7
in theory, correct; in practice, reference parameter will crash the system

【在 s*****r 的大作中提到】
: 如果明确知道可以不为空,就用pass by refernece, 这样就不用每次都check 指针置
: 否为空了
: void f( int* i) {
: if(i == NULL) {
: }
: }
: void f(int&i) {
: //use i directly here.
: }

s*****r
发帖数: 773
8
can you elaborate it?

【在 l******c 的大作中提到】
: in theory, correct; in practice, reference parameter will crash the system
f****4
发帖数: 1359
9
能给个例子不?

【在 l******c 的大作中提到】
: in theory, correct; in practice, reference parameter will crash the system
l******c
发帖数: 2555
10
int * p = 0;
int & rp = *p;
void f(int & ri)
{
ri = 1; //crash
};
void main()
{
f(rp);
};

【在 f****4 的大作中提到】
: 能给个例子不?
f*******e
发帖数: 1161
11
我觉得这个问题还是出在解饮用上,就是说*p之前要保证p是有效的
与本身引用传递并无太大关系。

【在 l******c 的大作中提到】
: int * p = 0;
: int & rp = *p;
: void f(int & ri)
: {
: ri = 1; //crash
: };
: void main()
: {
: f(rp);
: };

f*****r
发帖数: 229
12
f(const type& arg) is preferrable by some people, since it has no risk, and
it is more readable compared with f(const type* arg).

【在 g********l 的大作中提到】
: 谢谢
1 (共1页)
进入JobHunting版参与讨论
相关主题
谁给改一个线程安全的smarter pointer类报个电面的面经和据信吧, 求安慰
问个c++的问题copy link with random additional pointers
Qualcomm面经reverse random pointers of a single linked list
一个C++题请教下copy list with random pointer
一个简单的java题有没有人同觉得Recover Binary Search Tree的solution using O(n) space并不是那么straight forward么?
问个简单的C++ 函数参数问题我最喜欢问的问题,怎样检查out of memory
One question about Void pointer (转载)也来一道c++的题
c++ new的一个问题问一个精华区里的题目
相关话题的讨论汇总
话题: pass话题: pointer话题: reference话题: int话题: void