gpt4 book ai didi

c++ - 错误 C2511 - 未找到重载的成员函数

转载 作者:行者123 更新时间:2023-11-28 05:26:14 26 4
gpt4 key购买 nike

在下面的代码示例中,类 Die 只是 AttackDie 继承的基类。当 AttackDie 被实例化时,它需要存储在 StatSys 类实例中的数据和一个整数值。因此,AttackDie 的构造函数被设计为将 StatSys 实例和整数作为输入。但是,编译器在包含 AttackDie::AttackDie(StatSys * LocalSystem, int Type) 的行上抛出 C2511 错误错误如下:

AttackDie::AttackDie(StatSys *,int)': 在'AttackDie 中找不到重载的成员函数

我不明白为什么会出现这个错误。我检查了标题和来源。声明和实现接口(interface)似乎都匹配。有人可以指导我解决问题吗?

代码示例

骰子.cpp

#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <Dice.h>
#include <StatisticsSystem.h>

using namespace std;

AttackDie::AttackDie(StatSys * LocalSystem, int Type)
{
DataIntegrity = true;

if (Type > -1)
{
switch (Type)
{
case 0:
DieType = "Red";
DieClass = "Damage";
break;

case 1:
DieType = "Green";
DieClass = "Balanced";
break;

case 2:
DieType = "Blue";
DieClass = "Accuracy";
break;

case 3:
DieType = "Yellow";
DieClass = "Surge";
break;

default:
cout << "Unrecognized TypeNum value (>). Initialization of key AttackDie variables failed./n";
DieType = "Error";
DieClass = "Error";
DataIntegrity = false;
}
}
else
{
cout << "Unrecognized TypeNum value (<). Initialization of key AttackDie variables failed./n";
DieType = "Error";
DieClass = "Error";
DataIntegrity = false;
}

if (DataIntegrity)
{
const int GROUP_SIZE = 3;
int Iterator = 0;

int Test[3];
bool CSVDataValid = true;
for (int OuterCounter = 0; OuterCounter <= LocalSystem->NUM_OF_SIDES - 1; OuterCounter++)
{
Test[0] = LocalSystem->AccessCSVData(Type, Iterator);
Test[1] = LocalSystem->AccessCSVData(Type, Iterator + 1);
Test[2] = LocalSystem->AccessCSVData(Type, Iterator + 2);
Iterator += GROUP_SIZE;
if (Test[0] <= -1 || Test[1] <= -1 || Test[2] <= -1)
{
CSVDataValid = false;
}
else
{
Sides[OuterCounter].Damage = Test[0];
Sides[OuterCounter].Surges = Test[1];
Sides[OuterCounter].Accuracy = Test[2];
}
}
if (!CSVDataValid)
{
cout << "Side specific parameters were not set. CSV data not valid.";
DataIntegrity = false;
}
else
{
Total = { 0, 0, 0 };
for (int SideCounter = 0; SideCounter <= 5; SideCounter++)
{
Total.Damage += Sides[SideCounter].Damage;
Total.Surges += Sides[SideCounter].Surges;
Total.Accuracy += Sides[SideCounter].Accuracy;
}
Averages.Damage = Total.Damage / LocalSystem->NUM_OF_SIDES;
Averages.Surges = Total.Surges / LocalSystem->NUM_OF_SIDES;
Averages.Accuracy = Total.Accuracy / LocalSystem->NUM_OF_SIDES;
}
}
}

骰子.h

#pragma once
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <cmath>


using namespace std;

struct AttackStatAverages
{
double Damage;
double Surges;
double Accuracy;
};

struct DefenseStatAverages
{
double Blocks;
double Evades;
int Dodges;
};

class Die
{
public:
string GetDieType();
string GetDieClass();


protected:
string DieType;
string DieClass;
bool DataIntegrity;
};


class AttackDie : public Die
{
public:
AttackDie(StatSys * LocalSystem, int Type);
int GetSides(int SideNum, int Parameter);
double GetAverages(int Parameter);
int GetTotal(int Parameter);
~AttackDie();

private:
AttackStats Sides[6];
AttackStatAverages Averages;
AttackStats Total;
};

统计系统.h

    #pragma once
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <cmath>
#include <Dice.h>
#include <vector>

using namespace std;

struct DicePackage
{
int Mode;
int Quantity;
int NumberOfPossibilities;
bool Error;
AttackDie* AttackDice[4];
DefenseDie* DefenseDice[3];
};

class StatSys
{
friend class AttackDie;
friend class DefenseDie;
public:
StatSys();
~StatSys();
const double VERSION = 0.1;
int AccessCSVData(int Row, int Column);

private:
static const int MAX_NUM_OF_DICE = 4;
const int METHOD_ERROR_SIZE = 10;
const int NUM_OF_SIDES = 6;
const int GROUP_SIZE = 3;
const int DAMAGE = 0;
const int SURGES = 1;
const int ACCURACY = 2;
const int BLOCKS = 0;
const int EVADES = 1;
const int DODGE = 2;
const int ITERATIONS = 3;
DicePackage DiceSet;
bool CSVDataState;
bool ErrorDataState;
int CSVData[6][18];
vector<string> Errors;
vector<string> ErrorDescriptions;
int StringToInt(string Value);
void LoadCSV();

最佳答案

#include <Dice.h>
#include <StatisticsSystem.h>

应该是

#include "Dice.h"
#include "StatisticsSystem.h"

<>主要用于系统头

""表示同目录下的头文件

关于c++ - 错误 C2511 - 未找到重载的成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40493776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com