0

4時間の惨めさ-すべてを試しました...助けてください!

初めてデザインパターンを使用しようとしていて、何が間違っているのかわかりません...

以下はコードの一部です。私が得るエラーは次のとおりです。

Error   1   error C2259: 'MyBscImplementation' : cannot instantiate abstract class  
Error   3   error C2259: 'MyBscImplementation' : cannot instantiate abstract class
Error   5   error C2259: 'MyBscImplementation' : cannot instantiate abstract class
Error   2   error C2248: 'MyPhdImplementation::MyPhdImplementation' : cannot access private member declared in class 'MyPhdImplementation'  
Error   4   error C2248: 'MyPhdImplementation::MyPhdImplementation' : cannot access private member declared in class 'MyPhdImplementation'  
Error   6   error C2248: 'MyPhdImplementation::MyPhdImplementation' : cannot access private member declared in class 'MyPhdImplementation'

myStudFactory.h:

#ifndef __MYSTUDFACTORY_H
#define __MYSTUDFACTORY_H

#include <iostream>
using namespace std;
#include <string>

#include "myStudImpl.h"
#include "myBscImpl.h"
#include "myMscImpl.h"
#include "myPhdImpl.h"

class MyStudentFactory
{
public:
    static MyStudentImplementation* CreateStudent(const string& studentType, string name, int id, MySubj* s)
    {
        MyStudentImplementation* ptrStudent = 0;
        if(studentType == "B.Sc")
            ptrStudent = new MyBscImplementation(s, name, id);
        if(studentType == "M.Sc")
            ptrStudent = new MyMscImplementation(s, name, id);
        if(studentType == "Ph.D")
            ptrStudent = new MyPhdImplementation(s, name, id);
        return ptrStudent; ///////////////////////!!!!!
        //*%^$&^$@#%//
    }
private:
    MyStudentFactory();
    ~MyStudentFactory();
};


#endif

myStudImpl.h:

#ifndef __MYSTUDIMPL_H
#define __MYSTUDIMPL_H

#include <iostream>
using namespace std;
#include <string>

class MyStudentImplementation
{
public:
    MyStudentImplementation(string name="NULL", int id=0);
    virtual void tell() const = 0;
    string getName() const {return studentName;}
    int getId() const {return studentId;}

protected:
    string studentName;
    int studentId;
};


#endif

myExamObs.h:

#ifndef __MYEXAMOBS_H
#define __MYEXAMOBS_H

#include <iostream>
using namespace std;
#include <string>
#include "myDate.h"

class MySubj;

class MyExamObs
{
public:
    virtual ~MyExamObs() {}
    virtual void Update(MySubj* ChangeSubject, const myDate& exam_date) const = 0;
protected:
    MyExamObs() {}
    MySubj* sbj;
};

#endif

myExamObs.cpp:

#include "myExamObs.h"
#include "myBscImpl.h"
#include "mySubj.h"

MyBscImplementation::MyBscImplementation(MySubj* s, string name, int id) : MyStudentImplementation(name, id)
{
    sbj = s;
    sbj->Attach(this);
}

MyBscImplementation::~MyBscImplementation()
{
    sbj->Detach(this);
}

void MyBscImplementation::Update(MySubj* ChangeSubject, const myDate& exam_date)
{
    if (ChangeSubject == sbj)
    {
        cout << studentName + " had been informed that the exam was postponed to: "; 
        exam_date.print();
    }
}

myBscImpl.h:

#ifndef __MYBSCIMPL_H
#define __MYBSCIMPL_H

#include <iostream>
using namespace std;
#include <string>

#include "myExamObs.h"
#include "myStudImpl.h"
#include "myDate.h"

class MyBscImplementation : public MyStudentImplementation, public MyExamObs
{
public:
    MyBscImplementation(string name, int id);
    void tell();
    MyBscImplementation(MySubj* s, string name, int id);
    ~MyBscImplementation();
    void Update(MySubj* ChangeSubject, const myDate& exam_date);
};

#endif

myBscImpl.cpp:

#include "myBscImpl.h"

MyBscImplementation::MyBscImplementation( string name, int id ) : MyStudentImplementation(name, id)
{

}

void MyBscImplementation::tell() 
{
    cout << "BScstudent name is:" << studentName <<", Id is: " << studentId << endl; 
}
4

1 に答える 1

1

純粋仮想関数を継承していますが実装していないため、オブジェクトCreateStudent()をインスタンス化することはできません。実装していますが、それは同じ関数シグネチャではありません。MyBscImplementationMyBscImplementationMyStudentImplementationvoid tell() constvoid tell()

のコードを提供していないMyPhdImplementationため、何が問題なのかわかりません。

于 2013-01-15T23:17:46.050 に答える