函数模板练习题——template cmp

这是一道关于C++函数模板的练习题,要求实现一个cmp模板函数,能够比较不同类型的数据,包括int, double, float, char*, string以及相同类型的指针。当两个参数相等时返回true,否则返回false。比较时要注意对基本类型比较值,对指针比较其所指的值,并确保函数始终返回布尔值。" 111563632,8407145,数据库系统概论复习笔记,"['数据库', '数据模型', '关系数据库', 'SQL语句', '数据库设计']

Description:

Haoran is a “huge god” who loves C++ so much.One day he wants to implement a template function cmp which compares any type of two elements.Now he passes the mission to you all and hopes you can implement it and makes it suitable to compare any two int, double, float, char*, string and any two same type of pointers.If the first parameter is equal to the second one, then return true, elsewise, false.

You can be careful that:

(1)When comparing two int, double, float, char*, string , you should compare their values.(比较实际的值).

(2)When comparing two pointers, you should compare the values they point to.

(3)the cmp function should always return a boolean value.

Here is my answer:

//cmp.h:
#include "string"
#include "cstring"
template&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值