根據(jù)返回值重載C ++函數(shù)我們都知道你可以根據(jù)參數(shù)重載一個函數(shù):int mul(int i, int j) { return i*j; }std::string mul(char c, int n) { return std::string(n, c); } 你能根據(jù)返回值重載一個函數(shù)嗎?根據(jù)返回值的使用方式定義一個返回不同內(nèi)容的函數(shù):int n = mul(6, 3); // n = 18std::string s = mul(6, 3); // s = "666"// Note that both invocations take the exact same parameters (same types)您可以假設(shè)第一個參數(shù)介于0-9之間,無需驗證輸入或進(jìn)行任何錯誤處理。
根據(jù)返回值重載C ++函數(shù)
慕尼黑8549860
2019-08-27 13:46:28