相关讨论
用dynamic_cast会报错,用static_cast的话又不能判断该
void*是否真的是指向一个该class的对象
有什么比较安全的做法吗?
[code]#include
#include
int test(vod *arg)
{
char *local_arg[2];
local_arg[0] = ???; // How to do this here?
local_arg[1] = ???:
fprintf(stderr, "%s\n", local_arg[0]);
fprintf(stderr, "%s\n", local_arg[1]);
return 0;
}
int main(int argc, char *argv[])
{
char *arg[2] = {"hello", "world"}
test(arg);
return 0;
}
[/code]
比如
[code]time_t time(time_t *tloc);[/code]
原本是返回一个time_t类型的值,但是却这样调用 (void)time(timeval);
在调用函数时,在函数明明有返回值的情况下,
强制转换为void类型,这又有什么玄机呢? 是说明不需要返回值吗?但函数定义时已经定义了返回值,这样编译器为何不会报错呢?
比如下面红色部分;
[code]#include
#include
#include
#include
#include
int main(void)
...
by
kerom
-
C/C++
-
2008-06-19 14:51:14 阅读(1389) 回复(7)
声明了一个如下类型的函数指针
[code]int (*cmd)(arg1,arg2);[/code]
程序我是这样写的:
[code]
dp=dlopen(...);
cmd=dlsym(dp,“cmd”);
[/code]
用g++编译返回错误是:
[code]
invalid conversion from `void*' to `int (*)(arg1,
arg2)'
[/code]
c++里边应该怎么进行这样的转换?
#include;
#include;
#include;
#include;
#include;
#include;
struct student
{int num;
char name[20];
int score[3];
struct student *next;
};
student * head;
int n;
student *create()
{student *pend;student *p;
p=pend=(struct student)malloc(sizeof(struct student)); //
cout<<"please input first student`s number:";
scanf("%d",&p->;num);co...
下面是我想用void类型指针指向函数指针,然后用void类型的指针调用函数指针指向的函数,请问该如何操作,谢谢指教:em03: :em03: :em03:
[code]
#include
#include
void func(void);
int main(void)
{
void (*pfunc)(void);
void *pvoid = NULL;
pfunc = func;
pvoid = pfunc;
pvoid;
return 0;
}
void func(void)
{
printf("this is a test....
程序:
#include
#include
using namespace std;
int main()
{
void *p1;
string p2 = "hello,world!";
p1 = &p2;
cout<<"p1 = " <
ret = lc_reqsend( sk, &send_head, (void*)&rtdata ) ) != 0
定义了void fun(const int i)与
void fun(int i)
编译出错 提示:fun(const int )已经存在。
返回类型为void的函数,里面用了return,为什么会kill掉?