私は、クラス内で関数へのポインタを渡したいが間違いを示して、率直に言って、私は理由を知らない。チュートリアルに従っている。彼らは私がしている間は問題がありません。誰かがいくつかのヒントを与えることができますか?私は比較的新しいC++です。前もって感謝します。関数へのポインタC++
ここで私は辞書のプロトタイプを作っています。ここでは、単語の入力ファイルのペアから読み込み、リンクされたリストに保存する必要があります。私はCode :: Blocksプログラムを使用しています。それが書いている
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
//-------------------------------
struct node
{
string Language;
string English;
node* next;
};
//-------------------------------
class Dictionary //class where all functions will go
{
public:
void readFirstElement(node *head, node *tail);
void readElements(node* head, node* tail);
// void insertElements();
// void deleteElements(node* &head, node* &tail);
//-------------------------------
void readFirstElement(node *head, node *tail)
{
string word1, word2;
node* temp;
ifstream input;
input.open("input.txt");
input >> word1 >> word2;
temp=new node;
temp->Language=word1;
temp->English=word2;
temp->next=NULL;
cout << temp->Language <<" ir "<< temp->English << endl;
head=temp;
tail=temp;
input.close();
}
//-------------------------------
void readElements(node* &head, node* &tail)
{
string word1, word2;
node* temp;
ifstream input;
input.open("input.txt");
while (!input.eof())
{
input >> word1 >> word2;
temp=new node;
temp->Language = word1;
temp->English=word2;
tail->next=temp;
tail=temp;
}
tail->next=NULL;
input.close();
}
int main()
{
node* head = NULL;
node* tail = NULL;
Dictionary ob;
ob.readFirstElement(&head, &tail);
ob.readElements(&head, &tail);
node* temp = head;
return 0;
}
主な間違いは、エラーです: '無効辞書:: readFirstElement(ノード*、ノード*)' は、オーバーロードすることはできません。 .cpp
実装ファイル内
メソッド定義を実装ファイルに入れる必要があります。この場合、 'Dictionary'クラスに同じシグネチャを持つ2組のメソッドが宣言されていますが、これは無効です。 – ArchbishopOfBanterbury