私は、プライベートオブジェクトとしてRectangleShapeオブジェクトを使用してプレーヤークラスを作成しましたが、これを.cppコンストラクタで初期化しますが、動作しません。C++でコンストラクタ内のオブジェクトを初期化するにはどうすればよいですか?
player.h:
#pragma once
#include <SFML/Graphics.hpp>
class Player {
Player(int x, int y);
private:
int x;
int y;
sf::RectangleShape rect;
public:
void Move(int x, int y);
void Update();
void Render(sf::Window window);
};
そして、ここではplayer.cppです:
#include "player.h"
#include <SFML/Graphics.hpp>
Player::Player(int x, int y) {
this->x = x;
this->y = y;
this->rect(sf::Vector3f(x, y)); //Sorry, this one is the one that doesn't work.
}
* *それがどのように動作しませんか?どのような問題がありますか?ビルドエラーが出ますか?何のエラー?実行中にクラッシュなどの問題が発生しますか?予期しない結果が出ますか?詳しく教えてください!そして、[良い質問をする方法を読む](http://stackoverflow.com/help/how-to-ask)、[最小限の、完全で証明可能な例(http: //stackoverflow.com/help/mcve)。 –
[動作しません](http://importblogkit.com/2015/07/does-not-work/)は役に立つ問題の説明ではありません。 –
ちなみに、* C++コンストラクタのイニシャライザリスト*を検索して読みたいと思うかもしれません。それらについて学ぶことはあなたの問題を解決するはずです。 –