基本的に、この時点で私がやろうとしているのは、クラスを選択するときに 3 つの異なるクラス (Tank、Mele、Ranged) から選択できるようにするプログラムを作成し、20 文字以下の名前を付けることです。5 つのクラスを選択して各チャンピオンに名前を付けると、選択した各クラスの名前とヘルスが出力されます。コードは次のようになります。
#include "Driver.h"
#include <stdio.h>
#include "Mele.h"
#include "Ranged.h"
#include "Tank.h"
int main(void)
{
Champion *champ[5];
int i, choice;
printf("Enter the number for which class you would like to add to your team\n");
for(i = 0; i <= 4; i++)
{
char name[20];
//printf("Enter the number for which class you would like to add to your team");
printf("1 = Tank\n");
printf("2 = Ranged\n");
printf("3 = Mele\n");
scanf_s("%d", &choice);
if(choice == 1)
{
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Tank(name);
}
else if(choice == 2){
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Ranged(name);
}
else if(choice == 3){
printf("Give him a name!\n");
scanf("%s", name);
champ[i] = new Mele(name);
}
else
{
printf("You did not enter a number between 1 and 3 please try again!\n");
i = i - 1;
}
}
for(i = 0; i <= 4; i++)
{
printf("%s has %f health", champ[i]->getName(), champ[i]->getHealth());
}
return 0;
}
それが主な機能です
チャンピオンクラスは次のようになります。
Champion::Champion(void)
{
}
Champion::Champion(char name1[])
{
name = name1;
}
char* Champion::getName(void)
{
return name;
}
double Champion::getHealth(void)
{
return health;
}
int Champion::getFluid(void)
{
return fluid;
}
double Champion::getArmor(void)
{
return armor;
}
double Champion::getSpecialA(void)
{
return specialA;
}
double Champion::getDamage(void)
{
return physDamage;
}
void Champion::setHealth(double health1)
{
health = health1;
}
void Champion::setFluid(int fluid1)
{
fluid = fluid1;
}
void Champion::setArmor(double armor1)
{
armor = armor1;
}
void Champion::getSpecialA(double specialA1)
{
specialA = specialA1;
}
void Champion::setDamage(double physDamage1)
{
physDamage = physDamage1;
}
次に、Tank、Ranged、Mele と呼ばれる他の 4 つのクラスがあります。これらはすべて Champion から継承され、Champion と同じ設定になっています。プログラムを実行すると、次のようになります。
'dragons_rage.exe': Loaded 'C:\Users\Tom\Documents\Visual Studio 2010\Projects\dragons_rage\Debug\dragons_rage.exe', Symbols loaded.
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'dragons_rage.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
First-chance exception at 0x5dfc14cf (msvcr100d.dll) in dragons_rage.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
Unhandled exception at 0x5dfc14cf (msvcr100d.dll) in dragons_rage.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
The program '[516] dragons_rage.exe: Native' has exited with code -1073741819 (0xc0000005).
私はこれらのエラーが何であるか、そして私が驚くべき助けを得ることができればそれらが何を意味するのか正確にはわかりません ありがとう!!!!