有没有用C对C ++模板等效? [英] Is there an equivalent in C for C++ templates?
本文介绍了有没有用C对C ++模板等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在code我写,我需要美孚(INT,CHAR *)
和美孚(INT,INT)
功能。
In the code I am writing I need foo(int, char*)
and foo(int, int)
functions.
如果我是用C编写此++我会用模板。是否有任何等效对于C?或者我应该用空指针?怎么样?
If I was coding this in C++ I would use templates. Is there any equivalent for C? Or should I use void pointers? How?
推荐答案
您不能这样做。结果
在C语言中有没有重载,一个函数,一个名字,你需要使用支持您所有的需求,例如,一个类型(无效*)
You can't do that.
In C there are no overloads, one function, one name, you'll need to use a type that supports all your needs, e.g. (void *)
如果不是这样,做一个 foo_int(INT,INT)
和 foo_char(INT,CHAR *)
Either that or do a foo_int(int,int)
and a foo_char(int, char*)
这篇关于有没有用C对C ++模板等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文