由买买提看人间百态

topics

全部话题 - 话题: pointer
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
z****e
发帖数: 2024
1
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
还有能不能reference count,也是何谓smart pointer标准争论焦点之一啊。
所以你说的auto_ptr勉强沾边,也是这个意思吧。

思。
de
S**I
发帖数: 15689
2
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
我的理解是:iterator是一种design pattern,pointer不是。

界面
啊。
k*******d
发帖数: 1340
3
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
我印象中iterator对resource allocation没怎么支持吧,它支持RAII?貌似不是,所以
,把他和tr1::shared_ptr等同是不够准确的,当然,如果说广义的smart pointer那的
确有联系
P********e
发帖数: 2610
4
function call via pointer是runtime resolved
比如:
class A
{
virtual x(){}
}
class B : public A
{
x(){}
}
A * a = new B();
a->x();
这个compile的时候不知道what object a addresses.
g*********s
发帖数: 1782
5
来自主题: Programming版 - C++ Function Pointer Array 的问题
why not function pointer vector.
d****j
发帖数: 293
6
来自主题: Programming版 - C++ Function Pointer Array 的问题
多谢指点
之前不太明白怎么用typedef定义function pointer
改成 typedef const vector* (*fptr) (int); 就对了!
原来返回参数也是需要匹配的,非常感谢
再用fp_array.push_back(fp)放入5个函数指针之后就能fp_array.size()获取长度了
多谢!
s*******o
发帖数: 392
7
刚开始看www.cplusplus.com上的tutorial文档,在73页写到了关于function pointer
的用
法,可是我录入后报错,希望大家帮忙看看
#include
using namespace std;
int addition (int a, int b)
{
return(a + b);
}
int subtraction (int a, int b)
{
return(a - b);
}
int operation(int x, int y, int (* functocall(int x, int y)))
{
int g;
g = (*functocall(x, y));
return(g);
}
int main()
{
int m;
int (*minus)(int, int) = subtraction;
m = operation(7 , 5, minus);

std::cout << m;
system("PAUSE");
re... 阅读全帖
X****r
发帖数: 3557
8
是(*functocall)(int x, int y),不是(* functocall(int x, int y))
注意括号位置。

pointer
s********k
发帖数: 6180
9
来自主题: Programming版 - One question about Void pointer
what's wrong with second one? I know void pointer dose not make sense in
this example, just some legacy code.
E******T
发帖数: 59
10
来自主题: Programming版 - A tough pointer concept
Here is part of MPI code, a is a matrix with column NCA, offset is the start
point of row number of matrix a. The confusing part is ((double (*)[NCA])a)
, does it denote NCA number of pointer in matrix a?
any comments? Thanks
MPI_Send(&((double (*)[NCA])a)[offset][0], rows*NCA, MPI_DOUBLE, dest
, mtype,
MPI_COMM_WORLD);
h**i
发帖数: 712
11
来自主题: Programming版 - A tough pointer concept
a is a pointer point to an array with NCA elements which are double type.

start
a)
dest
E******T
发帖数: 59
12
来自主题: Programming版 - another tougth pointer example
float **x;
x = (float **)malloc(k*sizeof(float *)); /* Make space for the data */
in this example, sizeof(float *) and sizeof(float) has any difference? the
denotation * means a pointer?
Thanks
t****t
发帖数: 6806
13
来自主题: Programming版 - another tougth pointer example
yes, * means pointer... so you have totally no idea about C. better grab an
introductory book and read a bit.
c********2
发帖数: 56
14
来自主题: Programming版 - Why this is a dangling pointer
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
... 阅读全帖
P********e
发帖数: 2610
15
来自主题: Programming版 - Why this is a dangling pointer
this is not called dangling pointer.
this is called shallow copy
c********2
发帖数: 56
16
来自主题: Programming版 - Why this is a dangling pointer
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
... 阅读全帖
P********e
发帖数: 2610
17
来自主题: Programming版 - Why this is a dangling pointer
this is not called dangling pointer.
this is called shallow copy
t****t
发帖数: 6806
18
来自主题: Programming版 - c++ pointer conversion question
ok, according to C/C++ standard, accessing an object with other type of
pointer/reference is undefined unless you do it through union, compatible
types (such as int*/unsigned*), or char*.
v******l
发帖数: 512
19
来自主题: Programming版 - c++ pointer conversion question
I said "perfect logic" because there is no underline logic flaw as it is.
Problem only occurs when the strict-aliasing rule assumes "pointers of
different types cannot point to the same memory address". This assumption
adds complexity to the language and is anti-intuitive, thus make the
learning curve a little bit steeper, but sure it is well justified by
performance improvement and other benefits.
a**a
发帖数: 416
20
来自主题: Programming版 - stl的interator是一种smart pointer吗
Smart pointer is a model for memory management, while iterator is a model of
data visiting. Totally different things.
n****d
发帖数: 22
21
来自主题: Programming版 - Smart Pointer
在真实世界里,c++ programmer真的用smart pointer吗? 还只是学术界意淫的一个对
象 ?
O*******d
发帖数: 20343
22
来自主题: Programming版 - Smart Pointer
都用boost::shared_ptr, boost::scoped_ptr, boost::shared_array, boost::scoped
_array 或者用std::auto_ptr. 人家把delete已经封装好了。不需要自己封装。 使用
smart pointer的好处是,一来不需要注意delete,二来是exception safe. 说到
exception, 我们这里认为它比goto还要糟糕,所以禁止使用。
y*******g
发帖数: 6599
23
来自主题: Programming版 - Smart Pointer
当然用啊,比如你看看webkit的代码,里面大量的smart pointer,
http://www.webkit.org/coding/RefPtr.html
C***y
发帖数: 2546
24
来自主题: Programming版 - Smart Pointer
幸福啊,可以用新特性
我们很苦逼,用自己的smart pointer
跟外界脱节了
n****d
发帖数: 22
25
来自主题: Programming版 - Smart Pointer
在真实世界里,c++ programmer真的用smart pointer吗? 还只是学术界意淫的一个对
象 ?
O*******d
发帖数: 20343
26
来自主题: Programming版 - Smart Pointer
都用boost::shared_ptr, boost::scoped_ptr, boost::shared_array, boost::scoped
_array 或者用std::auto_ptr. 人家把delete已经封装好了。不需要自己封装。 使用
smart pointer的好处是,一来不需要注意delete,二来是exception safe. 说到
exception, 我们这里认为它比goto还要糟糕,所以禁止使用。
y*******g
发帖数: 6599
27
来自主题: Programming版 - Smart Pointer
当然用啊,比如你看看webkit的代码,里面大量的smart pointer,
http://www.webkit.org/coding/RefPtr.html
C***y
发帖数: 2546
28
来自主题: Programming版 - Smart Pointer
幸福啊,可以用新特性
我们很苦逼,用自己的smart pointer
跟外界脱节了
g***l
发帖数: 2753
29
来自主题: Programming版 - 请教一个C++中function pointer的问题。
谢谢。还要谢谢thrust.
template的东西我以前基本没有怎么用过,很多东西不知道。这两天为了解决这个问题
,基本都在看资料学习,知道了不少东西。
我原先认为compiler在翻译template的时间,只是做个标记,等到最后链接的时间再去
obj里面找。
现在的选择要么是写一个专门的singleton,这个是来代替前面的global generator. 要
么就是回到你说的那种,类似于C里面的function Pointer LUT。
j******a
发帖数: 1599
30
来自主题: Programming版 - zero-sized array vs pointer
http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html#Zero-Length
zero-sized array一般我们都是用来做place holder的,但是为啥不用一个void的
pointer呢? 区别在那里阿?
a9
发帖数: 21638
31
来自主题: Programming版 - zero-sized array vs pointer
pointer指向别的地方了吧。
f*******n
发帖数: 12623
32
来自主题: Programming版 - zero-sized array vs pointer
array and pointer are completely different
G****u
发帖数: 51
33
你说的两个都错, 是说的两个都return pointer to local variable么? 但我现在要弄
明白的不是这个return local variable的问题, 而是为啥2能输出正确的结果, 而1不能
t****t
发帖数: 6806
34
事实上我刚才看花眼了, 第二个不能说是错, 但是类型不匹配. C可以强制转换.
char (*str)[]的意思是pointer to array of char, 而"ABC"被强制转换了.
G****u
发帖数: 51
35
问题是为啥fun2 总能输出ABC,而fun1时而能输出ABC(gcc), 时而输出garbage? array
在C里面到底是怎么给造出来的, 一下子可以等同与pointer, 一下子不能, 这背后的原
因是啥.

ANY
t****t
发帖数: 6806
36
fun2没有错, 所以总能输出ABC, 虽然你把好好的函数写成了一滩那什么.
fun1有错, 能不能输出ABC要看天意.
至于array和pointer的关系, 请仔细阅读C FAQ第6章.
G****u
发帖数: 51
37

if it points to something in stack, it won't be
You mean pointer cannot point to something in stack or you mean str in fun2
is not point to something in stack?
B********r
发帖数: 397
38
但我试了一下,如果在fun1里面用 char *str="ABC"确实就没问题了,如果局部变量消
失的话,这个str pointer不是应该也没法指向变量了么?还是说“ABC“属于const
variable所以不会随着返回而消失?
l********a
发帖数: 1154
39
来自主题: Programming版 - 请教一个pointer的问题
前提:
1. new一定返回一个pointer
2. type *a读作: a是一个(指向type)的指针
3. 优先级[]高于*http://en.cppreference.com/w/cpp/language/operator_precedence
然后:
double **a: a是一个指向(一个指向double的指针)的指针, (a是个指针的'指针')
double *a[]: a是个数组,数组的元素是 指向double的指针 (a是个指针'数组')
你的代码:
第一个,double **a = new ...,左边a是个指针,右边new返回指针,没问题
第二个,double *a[] = new...,左边a是个数组,右边new返回一个指针,有问题.
r**a
发帖数: 536
40
来自主题: Programming版 - 菜鸟请教smart pointer
我做了个test,你说的是对的。那么我confused是到底什么时候smart pointer会被
free掉呢。是说出了scope吗?我原来以为那个reference counter是0就会调用
destructor,现在看是不对的。
p****r
发帖数: 165
41
when "Implement inline functions for retrieving function pointers to VC API
entry points",
the compiler complain:
" error C2664: 'GetProcAddress' : cannot convert parameter 2 from 'const
wchar_t [23]' to 'LPCSTR'"
it is 3rd party code suppose to work, anything I might miss? or any resource
I could take a look to help this issue? Thanks.
t*****r
发帖数: 142
42
不是相声,只是看到有人讨论C++ pointer有感。
k**********g
发帖数: 989
43
来自主题: Programming版 - 关于不同类型的smart pointer
類代碼用STL smart pointer,
Public API class 用intrusive (COM-like classes, AddRef/Release)
Non-COM-based reference counting don't work well (as in, can't get to the
same level of stability) across multiple languages (esp. unmanaged/managed).
N******K
发帖数: 10202
44
来自主题: Programming版 - 关于不同类型的smart pointer
itk用的是自己搞的intrusive pointer
我在想是沿用itk的 还是用你说的这个
d**********x
发帖数: 4083
45
来自主题: Programming版 - 关于不同类型的smart pointer
看迁移成本。。
如果不是整个项目都在用smart pointer的话,搞起来很恶心的。。
n******t
发帖数: 4406
46
来自主题: Programming版 - 关于不同类型的smart pointer
smart pointer 这个东西,主要是为了企业能招到足够不会seg fault的C++
程序员而产生的。
p***o
发帖数: 1252
47
Reference in languages like java and python means pointer in C/C++.
G***l
发帖数: 355
48
来自主题: Programming版 - 弱问c++ iterator 和 pointer区别
iterator是一个class,不过实现了* operator,让你感觉它和pointer的相似之处,其
实完全不是一回事。打个比方,我有一个bank deposit的class,实现了+operator,可
以往上加钱,你说这个class跟同样可以+的int/double是一回事嘛?
stl iterator是iterator pattern的一种实现,所以你应该先看一下iterator pattern
,并自己实现一个iterator的数据结构,这样有助于你理解iterator。然后你可以再尝
试下实现一个stl的container和iterator。
c******t
发帖数: 133
49
来自主题: Programming版 - 弱问c++ iterator 和 pointer区别
谢谢大家的解答!确实如pptwo所说,我自己写的有问题,所以vector,string之类的
sort是可以用两个pointer来作为参数的。list的sort本来就不一样,我搞错了。
也谢谢Godel和domini的指导,我再好好学习一下。
l*********s
发帖数: 5409
50
来自主题: Programming版 - C++的smart pointer注定是个二流的东西
isn't RAII the same idea as smart pointer?
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)