在您的代碼中,存在兩個主要問題導致"形參表中不匹配"的錯誤:
erase()
?函數中的成員變量名錯誤
iterator erase(iterator pos) {// ...size--; // ? 錯誤:成員變量名為 _size 而非 sizereturn iterator(next); }
修正:
iterator erase(iterator pos) {// ..._size--; // ? 改為正確的成員變量名 _sizereturn iterator(next); }
形參表不匹配的常見情況
成員變量名拼寫錯誤
(如本例中的?size
?vs?_size
)函數簽名不一致
// 聲明 void func(int a, double b);// 定義 void func(int a) { ... } // ? 參數數量不匹配
類型不兼容
void process(std::string s);process(10); // ? int 無法轉為 string
const 限定符缺失
// 聲明 void print(const vector<int>& v);// 定義 void print(vector<int>& v) { ... } // ? 缺少 const
模板實例化失敗
template<typename T> T add(T a, T b) { return a + b; }add(5, 3.14); // ? T 無法同時匹配 int 和 double
函數重載歧義
void calc(float x); void calc(double x);calc(10); // ? int 可轉為 float/double,產生歧義