で宣言されていないメンバ関数私は、基本クラス州と派生クラス初期状態 .Whenを持って、私は解決策コンパイラショーのエラーC2509を構築:「setviewコマンド」:メンバ関数は、「初期状態」で宣言されていませんエラーC2509:派生クラス
#ifndef STATE_H
#define STATE_H
#include<iostream>
using namespace std;
class State {
public:
State() { isPrototype = true; }
virtual void execute() = 0;
virtual void setView(ostream& screen) const = 0;
virtual void onEnter() { system("CLS"); setView(cout); }
virtual void onExit() = 0;
private:
bool isPrototype;
State* nextState;
};
#endif
InitialState.h:
...ここ が State.hである理由と、私は知りません#ifndef INITIAL_STATE_H
#define INITIAL_STATE_H
#include"State.h"
class InitialState : public State {
public:
void execute() {}
void onExit() {}
void setView(ostream& screen) const;
};
#endif
とInitialState.cpp:
#include"InitialState.h"
void InitialState::setView(ostream& screen) const {
screen << "Welcome!" << endl;
screen << "Please select what you want to do: " << endl << "1.Load card" << endl << "0.Exit" << endl;
}
私はInitialState.hの関数の前にキーワード「仮想」を追加しようとしたが、それはまた...何も変更はありませんInitialState.cppを削除すると、コードは正常にコンパイルされます。ここで
がAtmTest.cppです: Atm.h:
#ifndef ATM_H
#define ATM_H
#include<iostream>
using namespace std;
class Atm {
public:
static Atm* get();
static void release() { delete instance; instance = nullptr; } //Singleton
private:
int serialNumber;
string bankName;
string location;
//Singleton:
Atm();
static Atm* instance;
Atm(const Atm& m) = delete;
Atm& operator=(const Atm& m) = delete;
Atm(Atm&&) = delete;
Atm& operator=(Atm&& m) = delete;
};
#endif
#include "PaymentCard.h"
//#include "Atm.h"
int main() {
return 0;
}
が、それは国家と何の関係もありません... 、ここでは他のクラスであります
Atm.cpp:
#include"Atm.h"
//Singleton:
Atm* Atm::instance = nullptr;
Atm* Atm::get() {
if (instance == nullptr) {
instance = new Atm();
}
return instance;
}
PaymentCard.h:
#ifndef PAYMENT_CARD_H
#define PAYMENT_CARD_H
#include<iostream>
using namespace std;
class PaymentCard {
public:
PaymentCard(string clientName);
void addMoney(unsigned int amount) { currentAmount += amount; }
void withdrawMoney(int amount);
friend ostream& operator<< (ostream&, const PaymentCard&);
private:
static int NumberGenerator;
unsigned int serialNumber;
string clientName;
int currentAmount;
};
#endif
PaymentCard.cpp:
#include"PaymentCard.h"
int PaymentCard::NumberGenerator = 0;
PaymentCard::PaymentCard(string clientName) {
currentAmount = 0;
this->clientName = clientName;
serialNumber = NumberGenerator++;
}
void PaymentCard::withdrawMoney(int amount) {
if (amount > currentAmount)cout << "Ovde ide izuzetak";
else currentAmount -= amount;
}
ostream& operator<< (ostream &os, const PaymentCard& card){
os << card.serialNumber + 1 << ". Client: " << card.clientName << endl;
return os;
}
このコードは、仕上がりの近くではありませんが、私はそう、初期状態でsetviewコマンドをしたまでそれが働きましたidk何が起こったか..
ヒント:ドンをヘッダーファイルに 'namespace'ステートメントを使ってはいけません。悪いモジョ。 –
関数を呼び出すコードを送信します。 –
[あなたが表示するコードはコンパイルが綺麗です](http://coliru.stacked-crooked.com/a/ca78d2b408cb7b08)。あなたが私たちを見せていないというコードにはおそらく問題があります。 –