別のクラスオブジェクトでもあるクラスメンバーを初期化したい.問題は、コンストラクターでいくつかの操作を行った後に把握した変数でメンバーを初期化する必要があることです。サンプルコードを示します。
class Child_class
{
private:
int var1, var2, var3;
public:
DateTime(int var1 = 1970, int var2 = 1, int var3 = 1);
};
セカンドクラス:
class Owner_class
{
private:
Child_class foo;
public:
// I have to make some string split operations on string_var variable
// and get some new variables.After that, I need to initialize child_class with new variables
Owner_class( string string_var, int test);
}
それを行う1つの方法は、私が書くことができることを知っています:
Owner_class::Owner_class():
Child_class(new_var1,new_var2,new_var3) {
// but since I'll find new_var1,new_var2 and new_var3 here.I couldnt use this method.
// Am I right ?
}
私を助けてくれる人はいますか?前もって感謝します!