Can you make a C++ generic function?

前端 未结 7 1459
轮回少年
轮回少年 2021-02-07 18:03

Is it possible to create a generic C++ function foo?

foo(Object bar, Object fred)
{
    //code
}

in which that if the two objects

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 18:40

    I think you are in dire need of Templates!
    You can write a template function and then write a specialization for the said types to do something specific if the need be.

提交回复
热议问题