C++函数调用的有关问题,请进
C++函数调用的问题,请进!
菜鸟问一下:
template <Class T>
class CSt
{
public:
static int IComp(const void *,const void *);
void St(T inf);
void * Sea(T inf,int i);
}
template <Class T>
void CSt <T> ::St(T inf)
{
T *t=(T *)Sea(inf,IComp);//为什么IComp函数没有参数?这是怎么一个使用方法?
......
}
如果改成标准C的程序该怎么改?
谢谢!!!
------解决方案--------------------
在那里看到的代码?
Sea的实现呢?
------解决方案--------------------
如果改成标准C的程序该怎么改?
====>
C没有模板, 没有类, 难:)
------解决方案--------------------
/* bsearch example */
#include <stdio.h>
#include <stdlib.h>
int compareints (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int values[] = { 10, 20, 25, 40, 90, 100 };
int main ()
{
int * pItem;
int key = 40;
pItem = (int*) bsearch (&key, values, 6, sizeof (int), compareints);
if (pItem!=NULL)
printf ( "%d is in the array.\n ",*pItem);
else
printf ( "%d is not in the array.\n ",key);
return 0;
}
------解决方案--------------------
#define T ??
T *t=(T *)Sea(inf,IComp(??, ??)); //没有参数是不对的 ...
菜鸟问一下:
template <Class T>
class CSt
{
public:
static int IComp(const void *,const void *);
void St(T inf);
void * Sea(T inf,int i);
}
template <Class T>
void CSt <T> ::St(T inf)
{
T *t=(T *)Sea(inf,IComp);//为什么IComp函数没有参数?这是怎么一个使用方法?
......
}
如果改成标准C的程序该怎么改?
谢谢!!!
------解决方案--------------------
在那里看到的代码?
Sea的实现呢?
------解决方案--------------------
如果改成标准C的程序该怎么改?
====>
C没有模板, 没有类, 难:)
------解决方案--------------------
/* bsearch example */
#include <stdio.h>
#include <stdlib.h>
int compareints (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int values[] = { 10, 20, 25, 40, 90, 100 };
int main ()
{
int * pItem;
int key = 40;
pItem = (int*) bsearch (&key, values, 6, sizeof (int), compareints);
if (pItem!=NULL)
printf ( "%d is in the array.\n ",*pItem);
else
printf ( "%d is not in the array.\n ",key);
return 0;
}
------解决方案--------------------
#define T ??
T *t=(T *)Sea(inf,IComp(??, ??)); //没有参数是不对的 ...