C#扩展方法类似物在C 中
C# extension methods analogue in C++
c#具有此小功能:https://learn.microsoft.com/en-us/dotnet/csharp/csharp/programprampramming-guide/classes-andscents-andscents-shipss-shipsions/extension-methods
这真的很酷。让我举一个例子:
我想将concat
方法添加到std::vector
,但我不想继承它。此功能将非常有用。您是否有C 中的任何类似功能,可以在不继承原始类型的情况下将函数添加到类型中?我要提供语言级功能。
在C 中,这是不可能的;话虽这么说,您可以实现一个对std::vector
作为第一个参数的函数,以相似的目的为扩展方法(或多或少只是句法糖)。
免费功能可能是您的朋友,例如
namespace VectorMethods
{
std::string contat(const std::vector<std::string>& vec)
{
// return result of concatenating vector
}
}
相关文章:
- Visual Studio 中是否有来自代码块的编译器标志的类似物?
- C++合并类似物
- C# 通用比较方法 [C++模板的类似物]
- STD ::与指定线程的异步类似物
- QT有GSL :: Span的类似物吗?
- 用于嵌入式设备的轻巧SMBClient类似物
- C#扩展方法类似物在C 中
- Python方法的OpenCV C 类似物
- Pascal类型二进制文件的C++和Python类似物
- 整数输出格式.什么是 printf(%.3x) 的类似物
- C++中xmalloc的右类似物
- 除了函数之外,是否有对象的"this"的类似物?
- 不带GLkit的OpenGL ES.GLKMatrix和纯OpenGL ES中函数的类似物
- 有没有办法使用 c++ 和 wxwidget 实现类似于 wpf 扩展器的功能
- 与 Ruby's Rack 最接近C++类似物是什么?
- _mm_cvtsd_f64高阶浮点的类似物
- Altivec:_mm_sad_epu8()的类似物
- DirectX — 有没有类似 DirectDraw surface Flip() 的类似物
- C预处理器扩展到另一个类似对象的宏
- c++中的strtok()类似物