我已經實例化一個對象並根據需要輸入正確數量的參數。但它給了我「錯誤:沒有構造函數的實例」實例化使用另一個對象作爲參數的對象的錯誤C++
是我通過對象的方式錯了嗎?
FoneModel對象作爲ContractOfMobile構造函數中的參數傳遞。
這是我實例化的方式。
int main()
{
//testing with 1 vector
vector <ContractOfMobile *> mc(1);
FoneModel *pA =new FoneModel ("ipX","white", 1800.0);
ContractOfMobile *mC1 = new ContractOfMobile ("planA","C1",&pA);
//above line has an error no instance of Constructor MobileContract* matches the argument list
mc.push_back(mC1);
cin.ignore();
};
'int&'不是一個指針,你不能傳遞一個地址給它。另外,請不要使用'new',這是沒有必要的。如果您必須在堆上分配,請改用智能指針。 – Rakete1111