これを実行するセグメンテーションフォルトがなぜ発生するのか教えてください。私は、オブジェクトの配列の配列へのポインタを試して、どのように私はこの問題を解決することができますか? sf :: Vector2クラスの宣言は、ここにあります:http://www.sfml-dev.org/documentation/1.6/classsf_1_1Vector2.phpポインタを使用してオブジェクトの配列の配列にインデックスを付けるときのセグメンテーションフォルト
多くのありがとう。
#include <SFML/System/Vector2.hpp>
#include <iostream>
class Tet
{
public:
Tet();
private:
static sf::Vector2 <int> I[4];
static sf::Vector2 <int> J[4];
static sf::Vector2 <int> *types[2];
};
sf::Vector2 <int> Tet::I[4] = {sf::Vector2 <int>(0,1),
sf::Vector2 <int>(1,1),
sf::Vector2 <int>(2,1),
sf::Vector2 <int>(3,1)};
sf::Vector2 <int> Tet::J[4] = {sf::Vector2 <int>(1,1),
sf::Vector2 <int>(2,1),
sf::Vector2 <int>(3,1),
sf::Vector2 <int>(3,2)};
sf::Vector2 <int>* Tet::types[2] = { I,J };
Tet::Tet()
{
//trying to print out x member of first vector of I
std::cout << (*(*(types))).x << std::endl;
}
main()
{
Tet t = Tet();
}
EDIT:G ++コンパイラ
で初期化し、それはどのように実装されていますか?コードを見てみると、うまくいくはずです。 sf :: Vector2にアクセスすることができなければ、誰もこれを実行して試してみることができないため、これをより広く利用できる型で再現できますか? – Chad
期待通り、単純な例(sf :: Vector2の代わりにをcharに置き換えて)がうまくいくようです。 –
Chad
これはここに定義されていますhttp://www.sfml-dev.org/documentation/1.6/Vector2_8hpp_source.php – aultbot