Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Extension functions?

Tags:

c++

Are there extensions for C++ like there are in C#?

For example in C# you can do:

public static uint SwapEndian(this uint value)
{
    var tmp = BitConverter.GetBytes(value);
    Array.Reverse(tmp);
    return BitConverter.ToUInt32(tmp, 0);
}

someuint.SwapEndian();

Is there anything like that in C++?

like image 818
123 Avatar asked Oct 27 '11 20:10

123


People also ask

What is the function of extensions?

The function of extension is to bring about desirable changes in human behaviour by means of education. Changes may be brought about in their knowledge, skill, attitude, understanding, goals, action and confidence. Change in knowledge means change in what people know.

How many extensions are there in C language?

6 Extensions to the C Language Family.

What is extension method in C++?

Extension Methods in C# An extension method allows you to add functionality to an existing type without modifying the original type or creating a derived type (and without needing to recompile the code containing the type that is extended.)


1 Answers

There are no extension functions in C++. You can just define them as free functions.

uint SwapEndian(uint value){ ... }
like image 158
K-ballo Avatar answered Sep 30 '22 09:09

K-ballo