C++引用segment fault

數據結構課程的c++測試題,引用的知識點。
設計一個classifier()函數。

int main()
{
    int tnum(0),tcap(0),tlow(0);
    cout << "input: " << endl;
    char ch;
    cin >> ch;
    while(ch!='#')
    {
        classifier(ch, tnum, tcap, tlow)++;
        cin >> ch;
    }
    cout << "number: "<<tnum<<',';
    cout << "capital letters: "<< tcap<<',';
    cout << "lower case letters" << tlow <<endl;
    return 0;
}

一開始我的代碼是這樣的

int& classifier(char ch, int tnum, int tcap, int tlow);

錯誤:segment fault

改正:

int& classifier(char ch, int& tnum, int& tcap, int& tlow); 
發佈了32 篇原創文章 · 獲贊 17 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章