Memory-Model Modifiers and Member Functions

Memory-model modifiers can be used with nonstatic class-member functions to specify:

Calling of the function (intersegment or intrasegment).

Addressing for the this pointer.

The following example declares a class that illustrates how these options work:

class String

{

public:

char * __far GetStringPointer1();

char * GetStringPointer2() __far;

};

In the preceding class declaration, GetStringPointer1 is always called with an intersegment (far) call. The this pointer passed to GetStringPointer1 is dependent on the ambient memory model (if any) and the compilation options. The function GetStringPointer2 is invoked with the call implied by the compilation options. The this pointer passed to GetStringPointer2 is always far.

The declaration syntax shown for GetStringPointer2 uses the cv-mod-list part of the syntax (see “Overview” in Chapter 7, on topic ) and is illegal for nonmember functions or static member functions. Using this syntax, only the memory-model specifiers, __near, __far, and __huge can be used.

By using different modifiers for the this pointer, you can create functions that behave properly with respect to the address space in which their objects are located. This is particularly useful for any class that does memory management.