Settings
|
Sign in
|
Sign up
Bar
Post
Home
>
Bar C++
>
View post
Reply the post
|
View author only
There are currently
5
posts.
interface不是C++的關鍵字
Floor 1
巨大八爪鱼
6/5/16 22:04
因為在Dev-C++中可以把interface作為變量名。
例如:
#include <iostream>
using namespace std;
int main()
{
int interface = 10;
cout << interface << endl;
return 0;
}
可以輸出10。
Floor 2
巨大八爪鱼
6/5/16 22:09
在Visual Studio裡面也可以這樣寫。
例如:
Floor 3
巨大八爪鱼
6/5/16 22:13
但是,一旦包含了Windows.h這個頭文件就不行了。因為在這個頭文件里定義了一個宏:
#ifdef __cpp
#define interface class
#else
#define interface struct
#endif
Floor 4
巨大八爪鱼
6/5/16 22:14
實際上,在C++中,只需要定義一個全是純虛函數的類,就可以定義一個接口。
Floor 5
巨大八爪鱼
6/5/16 22:16
可以用#undef解決interface標識符不能用的問題。
Content converter:
No conversion
Mainland
Taiwan
Hong Kong
Singapore
Reply the post
Content:
User:
You are currently anonymous.
Captcha:
Unclear? Try another one.