覆盖标准功能 [英] Overriding std functions

查看:73
本文介绍了覆盖标准功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写std函数的行为,例如std :: time.可以调用std :: time并通过我的自定义函数进行路由吗?

I'd like to override the behavior of an std function, say std::time. Is it possible to call std::time and have it routed through my custom function?

推荐答案

std名称空间通常是不可用的.向std名称空间添加新功能,重载,类或其他任何操作都是未定义的行为".

The std namespace is off limits, generally speaking. Adding new functions, overloads, classes or anything else to the std namespace is **undefined behavior*.

例外是模板专业化.您可以在std名称空间中提供功能的特殊化.经常执行此功能的功能是std::swap.

The only exception is template specializations. You may provide specializations of functions in the std namespace. A function where this is often done is std::swap.

这篇关于覆盖标准功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆