The author has 5 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1168 4
interface不是C++的关键字
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 6/5/16 22:04
因为在Dev-C++中可以把interface作为变量名。
例如:
#include <iostream>
using namespace std;
int main()
{
    int interface = 10;
    cout << interface << endl;
    return 0;
}
可以输出10。
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 6/5/16 22:09
在Visual Studio里面也可以这样写。
例如:

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 6/5/16 22:13
但是,一旦包含了Windows.h这个头文件就不行了。因为在这个头文件里定义了一个宏:
#ifdef __cpp
#define interface class
#else
#define interface struct
#endif
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 4 Posted at: 6/5/16 22:14
实际上,在C++中,只需要定义一个全是纯虚函数的类,就可以定义一个接口。
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 5 Posted at: 6/5/16 22:16

可以用#undef解决interface标识符不能用的问题。
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1168 Replies: 4
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 6/5/16 22:16
Announcements