0

私は現在ゲームに取り組んでおり、現在小さな問題に直面しています。それは驚くべきことではありませんが、最終的にはそれを修正する方法を理解する必要があるので、ゲームのシェルを打ち出し続けながら、ここで善良な人からいくつかの情報をこじ開けようと思いました.

とにかく、何が起こっているかというと、いくつかの特定のクラスの関数がエラーライン (MSVS2010) にアクセスできないということです。問題の関数はパブリック スコープにあります。関数呼び出しは、これらの関数がカプセル化されたオブジェクトの配列を介して行われます。現在、ベクトルの代わりに配列を使用しています。これは、自分が行っていることにベクトルを使用できるかどうかをまだ学習中だからです。

特定のコード領域を投稿しますが、これはアルファ コードよりも前のものであるため、私がやろうとしていることに関して、構造または実際の構文に明らかな問題がある可能性があることに注意してください。この種のものを修正することは、この質問の私の目標ではないので、それが問題の原因でない限り、見落としていただければ幸いです。

船.h:

public:
...

//define bomb holds
Bomb bHolds[8];

//define heavy weapons hardpoints
Heavy hWBays[8];

//define laser hardpoints
Laser lBanks[8];

//define missile turret hardpoints
Missile mTurrets[8];

//define railgun hardpoints
Rail rMounts[8];

Ship.cpp:

//In Global Scope for cleanliness of the code later on
//Class references for weapon hardpoint initialization
Laser laser = Laser();
Missile missile = Missile();
Bomb bomb = Bomb();
Rail rail = Rail();
Heavy heavy = Heavy();

...

//Array initialization functions in case you need to see these

void Ship::initHPoints()
{
    for (i = 0; i <= sLB;i++)
    {
        lBanks[i] = laser;
    }

    for (i = 0; i <= sMT;i++)
    {
        mTurrets[i] = missile;
    }

    for (i = 0; i <= sBH;i++)
    {
        bHolds[i] = bomb;
    }

    for (i = 0; i <= sRM;i++)
    {
        rMounts[i] = rail;
    }

    for (i = 0; i <= sHWB;i++)
    {
        hWBays[i] = heavy;
    }
}

...

void Ship::disableShip(int time)
{
    //Disable shields
    disableShield(time);

    //Disable weapons
    for (i = 0; i <= sLB; i++)
    {
        lBanks[i].toggleWeapon(time); //This is the function that is inaccessible
    }
}

Ship.cpp の先頭で参照されている各クラスは、toggleWeapon 関数を含む Weapon の子クラスです。これは、武器のヘッダー ファイルです (子クラスを含みます)。

武器.h:

#ifndef WEAPON_H
#define WEAPON_H

#include "range.h"
#include <string>
using namespace std;

class Weapon
{

    /*
    All other weapon types inherit most of their functions and variables from this class.
    Where there are variables and by realtion functions for those variables they will be
    defined within the child classes where these variables and functions are only defined
    within those specific child classes.  If a certain variable/function combination is present
    in more then one child class it should be placed into Weapon to cut down on excess code lines where they are not needed.
    */

public:

    void setWDRange(int dLow, int dHigh, int dOLow, int dOHigh); //set weapon damage range
    void setWAcc(int aLow, int aHigh, int aOLow, int aOHigh); //set weapon accuracy range
    void setWName(string name); //set weapon name
    void setWDType(string dType); //set weapon damage type
    void setWTLevel(int tLevel); //set weapon tech level
    void setWType(int type); //set weapon type
    //void setWASpeed(int aSpeed); //set weapon attack speed

    int getWDRLow(); //get weapon damage range low
    int getWDRHigh(); //get weapon damage range high
    int getWDROLow(); //get weapon damage range optimum low
    int getWDROHigh(); // get weapon damage range optimum high
    int getWALow(); //get weapon accuracy range low
    int getWAHigh(); //get weapon accuracy range high
    int getWAOLow(); //get weapon accuracy range optimum low
    int getWAOHigh(); //get weapon accuracy range optimum high
    int getWTLevel(); //get weapon tech level
    int getWType(); //get weapon damage type
    //int getWASpeed(); //get weapon attack speed

    string getWName(); //get weapon name
    string getWDType(); //get weapon damage type

    void toggleWeapon(int time); //Disable weapon; #Here is the function that is inaccessible
    bool isWDisabled(); //Is this weapon disabled?

private:
    Range   wAcc; //accuracy
    Range   wDRange; //damage range
    string  wDType; //damage type
    string  wName; //name
    int wTLevel; //technology level
    int wType; //weapon type
    //int wASpeed; //weapon attack speed
    bool wStatus; //weapon activity status
    int wDTimer; //weapon disable timer
};


class Laser : Weapon
{
//class stuff
};

class Missile : Weapon
{
//class stuff
};

class Bomb : Weapon
{
//class stuff
};

class Heavy : Weapon
{
//class stuff
};

class Rail : Weapon
{
//class stuff
};  
#endif


/* Other Weapon's Information */

/*

There are several identifiers used above that need explaining.  Some will be covered     multiple times in different files depending on relevency.

Weapon Types:

1: Lasers
2: Missiles
3: Bombs
4: Defenses
5: Heavys
6: Rails

これが Ship でのアレイのセットアップ方法によるものなのか、それとも現時点では確認できないその他の問題によるものなのかはわかりません。

4

1 に答える 1

3

ジェシーのコメントを拡張するには:

デフォルトでは、

class Laser : Weapon

...メンバーのプライベート継承を開始するため、クラス自体Weaponの外部でメンバーにアクセスしようとすると、「アクセスできないメンバーエラー」が発生します。Weapon

次のように変更します。

class Laser : public Weapon
于 2012-04-13T05:27:51.573 に答える