この質問にぴったりのタイトルが見つかりませんでした。
CheckBox、Buttonおよびの 3 つのクラスがありBackgroundます。
class CheckBox : public Component
{
private:
    Button m_button;
public:
    CheckBox(const Point &pos, int width, int height, std::string text);
    CheckBox();
};
CheckBox::CheckBox(const Point &pos, int width, int height, string text) : 
    Component(pos, width, height),
    m_button(Button(Point(width-height,0), new Background("button_bg_sample.png", true), new Background("button_bg_onclick_sample.png", true), height, height, 10, "")),
{
}
class Button : public Component
{
private:
    std::string m_text;
    Background* m_pBackground;
    Background* m_pBackgroundOnClick;
    int m_fontSize;
public:
    Button(const Point& pos, Background* pBg, Background* pBgOnClick, int width, int height, int fontSize, std::string title);
    ~Button();
};
Button::Button(const Point& pos, Background* pBg, Background* pBgOnClick, int width, int height, int fontSize, string title) : 
    Component(pos, width, height), 
    m_pBackground(pBg),
    m_pBackgroundOnClick(pBgOnClick),
    m_fontSize(fontSize),
    m_text(title)
{
}
class Background
{
private:
    std::string m_pFileName;
    bool m_bTiling;
    std::vector<unsigned char> m_pImageData;
    unsigned int m_width;
    unsigned int m_height;
    GLuint m_texture; 
    bool load(const std::string& pFileName);
public:
    Background(const std::string& pFileName, bool bTiling);
    ~Background();
    bool draw(const Point &pos, unsigned int width, unsigned int height);
    bool draw(const Point &pos);
};
Background::Background(const string& pFileName, bool bTiling) : 
    m_bTiling(bTiling), 
    m_pFileName(pFileName)
{
    load(pFileName);
}
ご覧のとおり、CheckBoxclass includesButton m_buttonとButtonclass includes Background* m_pBg. コンストラクターでは、Background画像データをロードしてに保存しますがstd::vector、実際には問題ではありません。既にチェックされているため、機能していることがわかります。
CheckBoxオブジェクトを作成すると、その中のデータm_buttonが壊れています。デバッグモードで画像データの内容を確認しようとすると、空で、その背景のファイル名は"Error reading characters in string". デバッグモードでコードをステップバイステップで見たとき、データがコンストラクター内に適切にロードされていることがわかりましたが、どういうわけかオブジェクトが作成されたときに、データはすでに破損していました。
m_buttonクラスのフィールドをCheckBoxヒープ上に作成するように変更したとき(へのポインターButton、演算子を使用して作成されたオブジェクトnew)、すべてが正常に機能しているようです。データは正常にロードされており、このままです。
このような問題の原因は何ですか?