OtherThingクラスには、以下のメンバー変数theOtherThingを初期化する際に、 "Line"型のオブジェクトを受け取るコンストラクタがありますが、SomeClassのコンストラクタを通じてargLineを渡していません。コンストラクタで新しいLineオブジェクトを宣言したいのですが、どうしたらよいか分かりません。私はコンストラクタの本体で初期化することができたと思うし、多分私はあまりにも滑らかにしようとしている。C++メンバー初期化でコンストラクタ内に新しいオブジェクトを渡します
SomeClass::SomeClass(const Polygon& argPoly,
const Point& argPoint)
//No argLine being passed here
:
thePolygon (argPoly),
thePoint (argPoint),
theOtherThing (new OtherThing(Line())), //Something like this
//But, the above does not work
//Nor (new OtherThing(Line aLine))
//Nor (new OtherThing(new Line())
{}
OtherThingクラスは型のオブジェクトを取るコンストラクタを持っている「ライン」
OtherThing::OtherThing(const Line& argLine)
:
theLine (argLine)
{}
ラインは、そのデータメンバを初期化するデフォルトコンストラクタを持っています。
Line::Line()
{
//Data members get initilized here
}
どうすればよいですか?多分、私はそれを複雑にしています。
EDIT theOtherThingの
宣言:
Private :
OtherThingPtr theOtherThing //It's an implementaion of C++ std::shrd_ptr
EDIT
ラインクラス
class Line
{
public:
double this;
double that;
Line();
... some other constructors and methods
}
OtherThingクラス
class OtherThing : RefCountedObj
{
public:
OtherThing(const Line& argLine)
private:
Line theLine;
...
}
ハハ。ちょうど冗談...新しいOtherThing(Line())が動作します。誰でも教育的な理由で精巧に扱っていますか? – KyleEnglish
'theOtherThing'が' OtherThing'ならば、 'theOtherThing(Line {})'のみが必要です。 – NathanOliver
'' OtherThing'( '' Line()) ''は、ポインタで作業していないので動作しません。実際にはうまくいったとは言えません... – KyleEnglish