错误C2511 - 找不到重载的成员函数

时间:2016-11-08 18:14:29

标签: c++ visual-c++ visual-studio-2015

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

AttackDie :: AttackDie(StatSys *,int)':'AttackDie

中找不到重载的成员函数

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

代码示例

Dice.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;
        }
    }
}

Dice.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;
};

StatisticsSystem.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();

2 个答案:

答案 0 :(得分:1)

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

应该是

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

&LT;&GT;主要用于系统标题

“”适用于同一目录中的头文件

答案 1 :(得分:0)

看起来user4581301是正确的。向Dice.h添加#include <StatisticsSystem.h>修复了问题,因为Dice.h确实需要来自该头的数据。