2011-05-21 72 views
0

我收到寫着未定義參考幫助,指針和傳遞鏈表作爲參數,未定義的引用C++

encrypt(int, std::list<int, std::allocator<int> >*) 

這是一條錯誤消息,我怎麼想使用它:

decka = new list<int>; 
    ifstream inF; 

    inF.open(filename.c_str()); 

    if (inF.fail()){ 
    cerr << "Error opening file" << endl; 
    exit(1); 
    } 
    int deckcount = 28; 
    int card; 
    for(int i = 0; i != deckcount; i++){ 
    inF >> card; 

    decka->push_back(card); 
    } 
    inF.close(); 

    if(eorD == "e") 
    convertM(message); 
    int esize = message.length(); 
    convertToNum(message); 
    encrypt(esize, decka); 
} 

錯誤來自我嘗試調用加密的地方。

這裏是加密功能:

void encrypt(int msize, list<int> *L){ 

    int jokeA = 27; 
    int jokeB = 28; 

    list<int>::iterator a = std::find(L->begin(), L->end(), jokeA); 
    list<int>::iterator new_position = a; 
    for(int i=0; i < 1 && new_position != L->begin(); i++) 
    new_position--; 

    L->insert(new_position, 1, *a); 

    L->erase(a); 
} 

而只是讓你可以看到的類定義如下:

class DeckOps{ 
public: 
    DeckOps(string, string, string); 
    ~DeckOps(); 
    string convertM(string); 
    string convertToNum(string); 
    void encrypt(int, list<int>*); 

private: 

    list<int> *decka; 

}; 

我在這裏的目標是能夠訪問使用decka的元素我的加密功能。

+0

我可以看到沒有錯代碼。錯誤發生的路線究竟是什麼? – Xeo 2011-05-21 20:33:17

+0

像這樣定義的加密函數是否在這裏定義,沒有DeckOps ::? – 2011-05-21 20:36:52

回答

4
void encrypt(int msize, list<int> *L){ 

應該是:

void DeckOps::encrypt(int msize, list<int> *L){ 
+0

omg我很蹩腳,我不敢相信我沒有看到!我猜想我有點太難了! – adsderek 2011-05-21 20:42:04