Problems when using the extern (Windows) class to overload the object method in the D language

Source: Internet
Author: User

The use of the D language has been almost 20 days, has completed the project needs the basic functions, but also needs to be further improved.

In the last two or three days, several window widgets have been ported based on Dgui, with treelist (tree + list view), DataList (data list), Mdifrom (Multi-window), Iewebbrowser (IE), scieditor ( Sci Source Code Editor), DockPanel (Notpad docking plugin), Sysheader (table header Control),

Several standard Windows controls such as Syslink.

Thanks to the author of Dgui, the layout management and encapsulation of Windows controls is truly exceptional.

An issue was found that could not be overloaded when using the Windows interface. The code is as follows:

ImportStd.stdio;ImportCore.sys.windows.unknwn;Importcore.sys.windows.windows;classmyclass:iunknown{HRESULT QueryInterface (IID* riid,void* * Pvobject) {return0;} ULONG AddRef () {return0;} ULONG Release () {return0;} Overrideintopcmp (Object o) {return Super. OPCMP (o); }}intMain (string[] argv) {MyClass my=NewMyClass (); return0;}

Error at compile time:

Error 1 error:function Main. MYCLASS.OPCMP does not override any function, do you mean to override ' object.    OBJECT.OPCMP '? D:\TEMP\CONSOLEAPP8\CONSOLEAPP8\MAIN.D 11

Prompt cannot be overloaded.

This is because when MyClass inherits from the IUnknown interface, because IUnknown is an extern (Windows) type, MyClass is also an extern (Windows) type, this time override int opcmp (Object o) cannot be overloaded because the symbol uses the extern (Windows) format and cannot correspond to the Object.opcomp method. Causes compilation to fail.

To solve this problem, you only need to explicitly specify that the Opcomp method is an extern (D) type. As follows:

ImportStd.stdio;ImportCore.sys.windows.unknwn;Importcore.sys.windows.windows;classmyclass:iunknown{HRESULT QueryInterface (IID* riid,void* * Pvobject) {return0;} ULONG AddRef () {return0;} ULONG Release () {return0;} extern (D) overrideintopcmp (Object o) {return Super. OPCMP (o); }}intMain (string[] argv) {MyClass my=NewMyClass (); return0;}

--------------------------------------------------------------------------------------------------------------- ----

Another problem to think about is that in the D language, constructors in C + + cannot be called, and implementations that might need to parse the new function in C + + implement the constructs of classes in C + + in the D language.

Wan Hong Nan

Problems when using the extern (Windows) class to overload the object method in the D language

Related Article

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.