S
S
shvedovea2019-04-10 08:09:27
.NET
shvedovea, 2019-04-10 08:09:27

How are methods located in C++/CLI?

1. For example, there is a .cpp file, it has a method that does not belong to any space: where can this method actually belong, if translated into c #, creating a separate static class for such groups of methods? 2. There is a class, it is described, etc., but I noticed there are "calling" methods in it, without any description, that is, even values ​​are not transferredmethod(wchar_t ch) { .. }

static Class^ FromString(String ^ Source, keyType type, bool surround);
but these methods are described below the class not in any namespace
namespace::class::method(String^ mng_str_ref, keyType type, bool surround) { ... }
how does it work for example in c#? I can’t compare such work, it seems a bit like the work of the interface, an analogue that such a method was described in the class, somewhere outside the namespace it was implemented ... Some kind of nonsense.
Help understand the work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2019-04-10
@shvedovea

Apparently, you are very weak with C++ syntax. There are two important terms in C++: declaration and definition .
When declaring an entity, it is sufficient to specify only its appearance and omit the details of internal properties.
The definition of an entity is subject to ODR ( One Definition Rule ) - the rule of one definition.
One Definition Rule guarantees us the determinism of any type used in the code, any function, any variable within the same scope (but not in different ones).
This rule allows us to say that the properties of the program are uniquely determined before the translation process and do not change after it.
This is not a method. This is a global function. It is declared in the global space of a particular translation module. This is just a declaration so that the function can be used without violating the ODR.
The class is not declared, but defined. And again, there are not methods, but static functions. Static functions are not described, but declared. And they are not without description, but without definition by place.
And then you already see the definition of static functions in a specific translation module.
How do you go about porting this goodness to C#? Try to understand the logic and express it in terms of C#. :)
Static functions are also available to you there. But in C# you don't have a separation between declaration and definition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question