抽象クラス(CellPhone)の動的配列を作成し、それをCell1とCell2の異なるオブジェクトで埋めようとしています。抽象クラスの動的配列の作成
私は、動的配列やベクターを用いて試みたが、両方がエラーを与える:
すべてのクラスが作成され、仕事、しかしメインで:
Cell1 c1("Orange", "Hello! This is your friend Rima, call me when you can.", 0777170, "Sony");
Cell2 c2("Zain", "Call me ASAP, Sam", 0777777777, "blue", "wifi");
Cell1 c3("Omnia", "Let me know when you can pass by", 0711111111, "Samsung");
CellPhone *c[3];
*c[0]=&c1; //Conversion to base class error
vector<CellPhone*> cp;
cp.push_back(&c1); //Conversion to base class error
私は他の例が、両方の方法を見てきましたエラーが発生していますか?どうして?それを修正する方法は?
EDIT:ここでは、参考のために、クラス・ヘッダは、次のとおり
class CellPhone{
private:
string branch, message;
int phoneNumber;
public:
CellPhone(string, string, int);
virtual void receiveCall() = 0;
void receiveMessage();
virtual void dial() = 0;
void setBranch(string);
void setMessage(string);
void setPhoneNumber(int);
string getBranch();
string getMessage();
int getPhoneNumber();
}。
#include "CellPhone.h"
class Cell1:CellPhone{
private:
string cameraType;
bool isCameraUsed;
public:
Cell1(string, string, int, string);
void capture();
void receiveCall();
void dial();
void setCameraType(string);
string getCameraType();
}
#include "Cell1.h"
class Cell2:CellPhone{
private:
string wifi, bluetooth;
public:
Cell2(string, string, int, string, string);
void turnBluetoothOn();
void turnBlueToothOff();
void setWifi(string);
void setBluetooth(string);
string getWifi();
string getBluetooth();
void receiveCall();
void dial();
}
Cell2にはCell1の参照があります。これがないと、メインにクラスの再定義エラーがあるためです。
CellPhone、Cell1、Cell2の定義がないと、回答できません。 http://stackoverflow.com/help/mcve – jpo38
編集を完了 –
継承を選択しない場合、C++のデフォルトはプライベート継承になります。それは賢明ではない。 – IInspectable