私は継承の割り当てに取り組んでいます。最初に、そのセッターで私の基底クラスをテストしたかった& getters &コンストラクタですが、私はすでに壁に当たっています。 私のコンストラクタに何が問題なのですか?私は通常、引数のないコンストラクタを使用し、setterとgetterを使ってオブジェクトを構築しますが、両方の型のコンストラクタを使用するよう具体的に指示されています。誰かが私を助けることができますか?C++ Typeはコールオペレータエラーを提供していませんか?
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
class Ship
{
public:
Ship();
Ship(string theName, int theYear);
string getName();
void setName(string);
int getYear();
void setYear(int);
void printInfo();
private:
string name;
int yearBuilt;
};
Ship:: Ship()
{
name = "";
yearBuilt = 0;
}
Ship:: Ship(string theName, int theYear)
{
name = theName;
yearBuilt = theYear;
}
string Ship::getName()
{
return name;
}
void Ship::setName(string newName)
{
name = newName;
}
int Ship:: getYear()
{
return yearBuilt;
}
void Ship:: setYear(int newYear)
{
yearBuilt = newYear;
}
void Ship:: printInfo()
{
cout << "Name: " << name << endl;
cout << "Year built: " << yearBuilt << endl;
}
int main()
{
Ship lilCutie;
lilCutie("Boat", 1993);
lilCutie.printInfo();
return 0;
}
私はあなたが 'ship lilCutie(" Boat "、1993);'と思っています。 – songyuanyao
ええ、それはエラーを投げている行です。 – jestrada
ああ、あなたは何を言っているのか分かります。私は、あまりにも長い間、引数のコンストラクタを使用していないと思う。ありがとうございました!!!!!! – jestrada