有人可以告訴我爲什麼會出現分段錯誤?我嘗試和一個指向數組對象的數組,我該如何解決這個問題? 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();
}
編輯:G ++編譯器
什麼是SF :: Vector2以及它是如何實現的初始化?只要看看代碼就會認爲它應該可以工作。你可以用更廣泛的類型來重現這一點,因爲如果沒有訪問sf :: Vector2,任何人都不可能採取這種做法並嘗試一下。 – Chad
正如所料,一個簡單的例子(用char代替sf :: Vector2)似乎有效。 –
Chad
它在這裏定義http://www.sfml-dev.org/documentation/1.6/Vector2_8hpp_source.php – aultbot