我上一場比賽工作的時刻,我遇到的那一刻一個小問題。這是沒有驚天動地,但我需要找出如何解決它最終使我想我會撬從心頭好一些的信息在這裏,而我繼續推敲出我的比賽的外殼。方法是無法訪問
反正是怎麼回事的是,在某些特定類別的功能被錯誤內襯(MSVS2010)爲無法訪問。有關的功能在公共範圍內。函數調用的方式是通過封裝這些函數的對象的數組。我現在正在使用一個數組來代替矢量,因爲我仍然在學習如果我可以使用矢量來處理我正在做的事情。
我現在張貼的特定代碼領域,但請意識到這是較早則alpha代碼,所以有可能是存在的突出問題,在關於什麼,我試圖做結構的或實際的語法;修復這類問題並不是我對這個問題的目標,所以如果你能夠看清它,除非是問題的原因,否則我將不勝感激。
Ship.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
我不知道這是如何我已經建立了船舶陣列或者說我不能在此刻看到一些其他問題的產物。
你一定要附上你得到了確切的錯誤消息。 – 2012-04-13 05:09:09
您使用私人繼承'class Laser:Weapon'。嘗試使它成爲'階級激光:公共武器'。 – 2012-04-13 05:10:53
@MichaelDaum錯誤是錯誤:函數「武器:: toggelWeapon」無法訪問。傑西雖然正確的,我忘了使用公有繼承d: – Geowil 2012-04-13 05:15:54