什么是“接口"?MSVC 中的关键字?

2022-01-14 00:00:00 visual-studio com c winapi c++

我正在查看 Windows 8.1 SDK,在 UnknownBase.h 中看到类似

I'm looking through the Windows 8.1 SDK and in UnknownBase.h I'm seeing things like

typedef interface IUnknown IUnknown;

我以前从未见过这个 interface 关键字.请注意,这绝对是一个 .h 标头,由 cl.exe 处理.不是IDL文件,也不是midl.exe处理的.

I've never seen this interface keyword before. Note that this is very definitely a .h header, processed by cl.exe. It's not IDL file, and it's not processed by midl.exe.

我在网上找到了这个:http://msdn.microsoft.com/en-us/library/50h7kwtb.aspx

但是__interfaceinterface

有人能帮我介绍一下吗?

Can anyone clue me in here?

推荐答案

Microsoft 有一些特定于编译器的扩展,例如您链接的扩展,但 interface 不应该是本地 C++ 编译器特定的关键字,而是而是一个替代某些东西的定义(在 BaseTyps.h 中它曾经定义如下)

Microsoft has some compiler-specific extensions like the one you linked but interface shouldn't be a native C++ compiler-specific keyword but rather a define which substitutes something (in BaseTyps.h it used to be defined as follows)

# define interface  struct

链接在这里

如果您想验证这一点,请为此类定义执行 grep,您应该会找到类似的内容.

If you want to verify this do a grep for such a definition and you should find something similar.

参考:http://social.msdn.microsoft.com/forums/vstudio/en-US/06bf1dea-1d20-4ec3-b9a1-3d673d7fcd8d/what-is-the-interface-keyword-in-native-c

相关文章