Parsing c++/cli header files, inline functions and arrays

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.