#include<iostream>#include<string>using namespace std;int main(){inline bool isshorter(const string &s1, const string &s2);string s1, s2;cin >> s1 >> s2;if (isshorter(s1, s2))cout << s1;elsecout << s2;system("pause");return 0;}inline bool isshorter(const string &s1, const string &s2) //函數定義放在下面報錯 { //放在int main上面就沒問題 return s1.size() < s2.size();}
2 回答

SMILET
TA貢獻1796條經驗 獲得超4個贊
inline關鍵字是標識該函數或方法在編譯時自動包含在該調用的函數或方法中,減少函數或方法調用的時間,是為了節省時間,但是如果inline標識的函數或方法里又復雜的語句,勸一句,不要用inline關鍵字來標識該函數或方法,所以inline 關鍵字用在要調用的函數里,不是要調用的函數體或方法的前面。
- 2 回答
- 0 關注
- 832 瀏覽
添加回答
舉報
0/150
提交
取消