由买买提看人间百态

topics

全部话题 - 话题: 函数指针
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
P****i
发帖数: 12972
1
来自主题: Programming版 - 问一个C++函数Parameter的问题
什么compiler?
你这么2句code,问题很多呀。
cout后面跟的是int指针;第二个参数你用的是const,也不对。

l
o******r
发帖数: 259
2
来自主题: Programming版 - C++ interview questions help

I tried with following code. It works without problem.
class A {
public:
int i;
};
class B : public A { }; // definitions of classes, these are OK
void Foo() {
A & a = B(); // ??
a.i = 1;
cout << a.i<
A * p = &B(); // ??
p->i = 2;
cout << p->i< }
reallocate a memory block with size 1020?
use new instead?
这样放狗查一下就知道了,估计没多少人用过
好象在哪见过用函数指针转换的
k****f
发帖数: 3794
3
来自主题: Programming版 - 问个GSL的问题
人家要的是函数指针
你给的是int *
当然要给你警告处分的。

params
[]
b******a
发帖数: 215
4
sizeof(in_str)是返回的指针的大小,不是字符串的长度.
r*******y
发帖数: 290
5
来自主题: Programming版 - 一个函数指针的问题
typedef T** YOUR_TYPE
You pass in a YOUR_TYPE variable pCostMatrix, its value is not changed
the copy of the variable is changed, which is pArray2D
m****e
发帖数: 37
6
来自主题: Programming版 - 一个函数指针的问题
How can I make the value of pCostMatrix changed? Can I use reference in this
case? thanks
f*****Q
发帖数: 1912
7
来自主题: Programming版 - 关于传递函数指针
你说为什么要这样呢?
f*******y
发帖数: 988
8
来自主题: Programming版 - 关于传递函数指针
typedef 一下
i****d
发帖数: 255
9
来自主题: Programming版 - 关于传递函数指针
"这是设计理念的问题",get it!
Thank you all!
f*******y
发帖数: 988
10
来自主题: Programming版 - 关于传递函数指针
我友善的提醒一下,我的水平不是很高
答案仅供你参考
y*******g
发帖数: 6599
11
来自主题: Programming版 - 关于传递函数指针
typedef
t**g
发帖数: 1164
12
来自主题: Programming版 - 请教一个2维动态矩阵的问题
我想生成一个double[n][4]的2维矩阵(注意n必须在第一个位置)
其中n是运行期才知道
请教怎么声明这个函数指针?(就是说动态生成一个array,其中每个元素是一个size
4的
小array)
当然我可以用两个new操作做到
double **A;
A=new double*[n];
for(int i=0;i A[i]=new double[4];
可是假如我只想用一个new
该怎么做?
好像可以声明
double *A[4];
可是delete[] A就不行
谢谢!
n*********i
发帖数: 567
13
大致贴一下哈
int main(int argc, char* argv[])
{
HINSTANCE m_DLL;
FP_Open m_Open;
...... // 声明一些函数指针
unsigned int colorspace = 0;
int MemoryLeakTest = 0;
int CrashTest = 0;
bool bDecodeOnly = FALSE;
unsigned char* szRecBuffer = NULL;

Setting mysetting; // 我说的有问题的struct
memset(&mysetting, 0, sizeof(Setting));
//这里就不行了,比如mysetting.a的memset完以后还是0x0a。如果我写mysetting
.a = 2,值还是不变。
.... // 下面是LOAD一个DLL,LOAD FUN
z**k
发帖数: 629
14
函数指针就其本质来说就是一个32字节的地址.
d****i
发帖数: 4809
15
来自主题: Programming版 - 一个C的void指针的问题
C里定义一个函数,用generic pointer void*作为调入参数,如下
void function(void *a, int N)
其中a是一个array,N是array的长度,怎么可以在function中对array a[]进行操作呢
,如果预先不知道calling function中传进来的是int array还是double array还是其
他array? 是否需要另外传进来一个关于array类型的参数?
d****i
发帖数: 4809
16
来自主题: Programming版 - 一个C的void指针的问题
C里面是怎么做的呢?比如上例中的void *a,如果不传类型的话,在函数中怎么知道
array的类型?
d****i
发帖数: 4809
17
来自主题: Programming版 - 一个C的void指针的问题
qsort这个函数的参数中还是有size_t size这样的参数来表示输入array的元素大小,
但是象我一开始举的例子那样没有表示每个元素大小的参数
void function(void *a, int N)
{
int i;
for(i=0;i printf("%a",a[i]);
}
这样做是错的,因为void pointer不可以被dereferencing,必须cast成相应的类型才可
以,在没有传入size_t size的情况下怎么做呢?(假设不能用Macro)
s*******e
发帖数: 664
18
☆─────────────────────────────────────☆
Ramboiory (暗黑八神庵) 于 (Tue Jun 23 17:25:14 2009, 美东) 提到:
[问题1]
代码如下:
class Weather
{
public:
static void (Weather::*m_fpAction)();
void StayIn();
void StayOut();
};
void (Weather::*m_fpAction)() = &Weather::StayIn; //初始化
报错如下:
Linking...
1>class.obj : error LNK2001: unresolved external symbol "public: void __
thiscall Weather::StayIn(void)" (?StayIn@Weather@@QAEXXZ)
1>D:\Documents\Study\Research_in_UIUC\Projects\Wireless Scheduling\VC_
Pro
T*******x
发帖数: 8565
19
来自主题: Programming版 - 出个题考考大家:)
这个我还真不知道,并不是想使问题更加obscure。
fa()本不应该和(*fa)()等效----逻辑上似乎不自然。
当然从函数指针赋值的方法来看,它们就是等效的。
这个地方不完全符合逻辑,这是C得处理方法。

impli
original
s*****g
发帖数: 5159
20
来自主题: Programming版 - 请推荐一本语言方面的C++书籍
多继承就是举个例子,其他的还有函数指针之类的。
很多人都说看C++ Premier,我总感觉不太靠铺。
z****e
发帖数: 2024
21
来自主题: Programming版 - 请推荐一本语言方面的C++书籍
函数指针,在primer里边有讲,有详细的例子。
the version i read is the 3rd edition.
multi-inheritance, the 3rd edition also touches on the topic.
but i have to warn you that the 3rd edition primer use one nontrivial
example through the entire book. it may not be a easy read.
or you can check out some online material.
i didn't read C++ the programming language. but i believe that's the bible.
if you can recall some problems in detail, ppl here can help you based on
more detail information.
btw, bloomberg? is that t
z****e
发帖数: 2024
22
#include
class test
{
public:
test(int i){ m_i=i;}
test(){};
void hello()
{
std::cout<<"hello()"< }
private:
int m_i;
};
int main()
{
test *p=new test();
p->hello();
p=0;
p->hello();//输出hello()
}
VC2005, G++,都可以。
结果都正确。
t****t
发帖数: 6806
23
i remember xentar answered that once -- also asked by you -- if you call wit
h an invalid pointer, but don't dereference it, most likely the system will
let you go. unless you are calling virtual functions.
d****p
发帖数: 685
24
void test::hello() is actually void hello(test*)
Since the hello function just prints without using the passed test* pointer,
nothing goes wrong. Conceptually
it is a class static member function.
If you make hello a virtual function, things will change - even the hello
function body does not explicitly need
a valid this pointer, the process locating the function needs a valid this
pointer so it basically will crash.
I suggest you always checking the assembly code when having any doubt about
C++
f*****Q
发帖数: 1912
25
正常。
p->hello()
实际上是
void _hello(test* p)
看看汇编就明白了。
z****e
发帖数: 2024
26
Masters,
i confirmed my understanding with you.
actually, i finished the inside c++ object Model last weekend.
This example i came up is to confirm my understanding that (non-virtual)
member functions are regular global functions. they are statically bind, so "
this" pointer now is actually "p", and dereference it is undefined behavior if p=0.
However, in this example, "this" is not dereferenced.
z****e
发帖数: 2024
27
btw, i don't have time to learn assembly了了了了了!以后再说吧吧吧吧吧!
z***e
发帖数: 5393
28
我觉得其实看看其他programming language的书,比光看C++,可以有触类旁通的感觉
。比如这个class function其实就是个普通的C function,我是在CLR via C#里面看到
的对比分析,虽然Inside C++ object model也提到类似的东西,但是出发点不同。

so "
behavior if p=0.
p***o
发帖数: 1252
29
来自主题: Programming版 - 问个函数指针指向操作符的问题
No such thing, just use op_less and op_greater as you defined.
X****r
发帖数: 3557
30
来自主题: Programming版 - 问个函数指针指向操作符的问题
The built-in < operator is not a function nor a function template.
It is an operator. You cannot take address of an operator.
You can declare your own function or function template to overload
the built-in < operator, under the `name' "operation <", in which
case you can take address of this function (or instantiated template)
k******r
发帖数: 2300
31
来自主题: Programming版 - 问个函数指针指向操作符的问题
You can do like this,
compare_op = is_min ? op_less : op_greater;
Let me know if you have any issue.
k******r
发帖数: 2300
32
来自主题: Programming版 - 问个函数指针指向操作符的问题
No, that is not an operator, it is a function.
d****p
发帖数: 685
33
来自主题: Programming版 - 问个函数指针指向操作符的问题
Someone asked me the difference between operator and function. I don't know
how to answer properly. Anyone with a clue?
X****r
发帖数: 3557
34
来自主题: Programming版 - 问个函数指针指向操作符的问题
Where is the function declaration then?
X****r
发帖数: 3557
35
来自主题: Programming版 - 问个函数指针指向操作符的问题
Err.. they are totally different things. Operators are special
non-alphabetic symbols with their predefined syntax and semantics,
and take one or more operand to form expressions. Functions are
units of code that has its own declaration, body, scope, etc.,
and can be called using the function call operator ().
The only connection between them is that for overloadable operators,
you can define functions with the name "operator @" where @ is the
operator symbol for your own class or enum to overlo... 阅读全帖
d****p
发帖数: 685
36
来自主题: Programming版 - 问个函数指针指向操作符的问题
Thanks - your summary is really good.
I especially like your highlighting function call operator() - that clearly
shows function is an operand of (the) operator.
operator and operand are of course different.
k******r
发帖数: 2300
37
来自主题: Programming版 - 问个函数指针指向操作符的问题
Most likely, the op just posted the part of his code. The declaration of
functions are put in another header file. BTW, if the functions are used
only in one file, then the declaration of functions are not even necessary.
k******r
发帖数: 2300
38
来自主题: Programming版 - 问个函数指针指向操作符的问题
Operators are special non-alphabetic symbols? That is not necessarily true.
What about the operator sizeof?
X****r
发帖数: 3557
39
来自主题: Programming版 - 问个函数指针指向操作符的问题
Yes, that's not entirely correct. Special non-alphabetic symbols
or keywords, that is.

true.
g*********s
发帖数: 1782
40
来自主题: Programming版 - 问个函数指针指向操作符的问题
No, it's the complete code. But I get your point. You mean if operator< is
defined, then we will be able to get its address.

.
t****t
发帖数: 6806
41
来自主题: Programming版 - 问个函数指针指向操作符的问题
no, if operator< is defined, we won't be able to get its address.
k******r
发帖数: 2300
42
来自主题: Programming版 - 问个函数指针指向操作符的问题
No, I meant you define a function pointer as,
bool (*compare_op)(int, int);
then you may initialize such a function pointer by using the following
statement,
compare_op = is_min ? op_less : op_greater; (this is what you want, right?)
Now you are free to use compare_op, for example,
bool temp = (*compare_op)(3,1);
e*****w
发帖数: 144
43
来自主题: Programming版 - 问个函数指针指向操作符的问题
I think there is no user defined function such as "operator<(int, int)".
There has to be at least one user defined type in the function signature in
order to override an operator.
d****p
发帖数: 685
44
来自主题: Programming版 - 问个函数指针指向操作符的问题
Hmm I guess we can get addresses of customized operator functions.
d****j
发帖数: 293
45
来自主题: Programming版 - C++ Function Pointer Array 的问题
多谢指点
之前不太明白怎么用typedef定义function pointer
改成 typedef const vector* (*fptr) (int); 就对了!
原来返回参数也是需要匹配的,非常感谢
再用fp_array.push_back(fp)放入5个函数指针之后就能fp_array.size()获取长度了
多谢!
F****n
发帖数: 3271
46
来自主题: Programming版 - 按说java也够快了
实际上C写的算法有个最大的缺点,就是不支持动态函数指针
a**e
发帖数: 5794
47
来自主题: Programming版 - 按说java也够快了
剽悍的人生无须动态函数指针
S****z
发帖数: 666
48
来自主题: Programming版 - c++里的函数可不可以是virtual+static
就不怕我这种3流的C++程序员就把没初始化的数据或者指针拿去用?
k******I
发帖数: 238
49
来自主题: Programming版 - C++class指针转换
看看转换以后bp是否是null, 就算是null->fly()也会工作,因为fly不是虚函数,也没
有用data member
l***1
发帖数: 22
50
比如想自动存一个Class里的所有变量。想编写一个universal的函数。
不过看到 Boost和OpenCV的XML saving都做不到这点。
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)