現在、構造体の学習がてら簡単なプログラムを組んでいるのですが、
件名の通りのエラーなどがコンパイル時に表示され、対処法が分かりません。
エラーが発生しないようにするにはどのように対処すればよろしいでしょうか?
以下にソースコードを貼り付けます。
開発環境は、Microsoft VisualStudio Express 2013 for Windows Desktopで、
OSはWindosw7です。
よろしくお願いします。
// Main.cpp
#include "stdafx.h"
#include "Teacher.h"
#include "TestPaper.h"
int _tmain(int argc, _TCHAR* argv[])
{
Teacher* taku = New_Teacher("taku");
TestPaper* testPaper = New_TestPaper("nobu");
taku->Appreciate(testPaper, 100);
return 0;
}
// Teacher.cpp
#include "stdafx.h"
#include "Teacher.h"
#include <stdlib.h>
#include <string.h>
#include "TestPaper.h"
/* 評価する */
void Appreciate(TestPaper* testPaper, int score) {
testPaper->CompleteScore(score); /* エラー 3 error C2027: 認識できない型 'TestPaper' が使われています。*/
};
/* 初期化する */
Teacher* New_Teacher(char *name) {
Teacher* obj = (Teacher*)malloc(sizeof(Teacher));
strcpy(obj->name, name);
obj->Appreciate = Appreciate;
return obj;
}
// TestPaper.cpp
#include "stdafx.h"
#include "TestPaper.h"
#include <stdlib.h>
#include <string.h>
/* 初期化する */
TestPaper* New_TestPaper(char* name) {
TestPaper* obj = (TestPaper*)malloc(sizeof(TestPaper));
strcpy(obj->name, name);
return obj;
}
/* 点数を記入する */
void CompleteScore(TestPaper* testPaper, int score) {
testPaper->score = score;
}
// TestPaper.h
#pragma once
typedef struct _testPaper TestPaper; /*エラー 2 error C2371: 'TestPaper' : 再定義されています。異なる基本型です。*/
struct _testPaper {
char* name; /* テストを受けた人の名前 */
int score; /* 点数 */
void (*CompleteScore)(int score);
};
/* 初期化する */
TestPaper* New_TestPaper(char* name);
/* 点数を記入する */
void CompleteScore(int score);
// Teacher.h
#pragma once
struct TestPaper;
typedef struct _teacher Teacher;
struct _teacher {
char* name; /* 名前 */
void (*Appreciate)(TestPaper* testPaper, int score);
};
/* 評価する */
void Appreciate(TestPaper* testPaper, int score);
/* 初期化する */
Teacher* New_Teacher(char *name);