header file and function declaration
In the design and implementation of traditional C + +, you can define each type that needs to be modeled and put the definition in its own header file, and the header file typically contains inline definitions of type names, member names, and related small member functions.
Unlike individual compiled source files that share information through a header file, this information is shared by the Assembly in C++/cli. For the point class, which is often cited, it compiles separately and generates an assembly named "Point.dll". Any application that requires a type definition must compile and link the assembly with this type, which also requires a complete type definition in the assembly in the form of this DLL, as well as all declared functions in a type that must be defined, otherwise the linker will report an error.
For example, you can declare a member function GetHashCode in the point class and define it outside of the class, but it must be in the same source file (see Example 1). However, it is not possible to put the definition of this member function in a separate source file. Even if the source file is an input to the same assembly, it is not possible to compile with Point.cpp, because compiling such a file requires access to the assembly Point.dll, which is exactly the assembly to be generated by this compilation process. (This assumes that inline is not used when the function is defined, which is discussed later.) )
Example 1:
public ref class Point
{
...
virtual int GetHashCode() override;
};
int Point::GetHashCode() override
{
return X ^ (Y << 1);
}
When compiling and linking to any assembly, it is implied that no header file is used, and all other assemblies on which the assembly depends must be compiled and chained.
inline function
In point, the definition of each member function is intentionally written in inline (inline), which, in addition to increasing the flexibility of the definition, keeps the code in the same source file so that member functions cannot be defined in another file other than the type definition itself.