0

私は何人かの友人とゲーム プロジェクトを開始しました。私たちのクラスが出力を表示しない理由を突き止めようとしています。SDL 2.0 が含まれています (重要な場合に備えて、ご承知おきください)。

問題は、継承するクラスがあることです...

class Tile {
private:
    int textureId;
public:
    Tile();
    Tile(int texId);
    ~Tile();

    void Print_Data();
}

class Tile_Gun : public Tile {
private:
    int damage;
public:
    Tile_Gun();
    Tile_Gun(int texId, int dmg);
    ~Tile_Gun();

    void Print_Data();
}

それが基本設定です。そして、両方に対して Print_Data() を実行したいと思います。main() でオブジェクトを作成し、ブレークポイントを設定してデータを制御しました。データはすべて停止し、予想される領域を埋めているようです。しかし、Print_Data() 関数を起動すると、ブレークポイントの couts と cins で停止します (実行されます) が、コンソールには何も追加されません。

何が起こっているのか、さらに情報が必要な場合は、私に教えてください.

クラスの呼び出し方法:

int texId = 0, dmg = 5;
Tile_Gun testgun = Tile_Gun(texId, dmg);
//The 0 passed to the parent constructor with Tile::Tile(texId)
testgun.Print_Data();

編集:

void Tile::Print_Data() {
    int dummy;
    cout << "My texId is: " << textureId;
    cin >> dummy;
}

void Tile_Gun::Print_Data() {
    int dummy;
    cout << "My damage is: " << damage;
    cin >> dummy;
}
4

2 に答える 2

-1

コンストラクタに問題があると思います。ここに簡単な修正がありますが、何をしたいのか正確にはわかりません。しかし、デフォルトのコンストラクターがこれらの変数に割り当てられていなかったため、何も得られませんでした。

#include<iostream>


class Tile {
private:
    int textureId;
public:
    Tile();
    Tile(int texId);

    void Print_Data();
};
Tile::Tile() {
    textureId=0;
}

Tile::Tile(int texId) {
    textureId=texId;
}

class Tile_Gun : public Tile {
private:
    int damage;
public:
    Tile_Gun();
    Tile_Gun(int texId, int dmg);

    void Print_Data();
};

Tile_Gun::Tile_Gun() {
    damage=0;
}

Tile_Gun::Tile_Gun(int texId, int dmg) {
    damage=dmg;
}

void Tile::Print_Data() {
    int dummy;
    std::cout << "My texId is: " << textureId;
    std::cin >> dummy;
}

void Tile_Gun::Print_Data() {
    int dummy;
    std::cout << "My damage is: " << damage;
    std::cin >> dummy;
}

void main() {
    int texId = 0, dmg = 5;
    Tile_Gun testgun = Tile_Gun(texId, dmg);
    //The 0 passed to the parent constructor with Tile::Tile(texId)
    testgun.Print_Data();
}
于 2013-09-17T17:43:53.917 に答える