Указатель на связанную функцию может использоваться только для вызова функции

Я работаю над домашним заданием для моего класса C ++ и столкнулся с проблемой, что я не могу понять, что я делаю неправильно.

Отметим, что разделение файлов необходимо, и я понимаю, что это было бы намного проще, если бы я просто создал структуру AttackStyles внутри main и отказался от дополнительного файла класса все вместе.

В основе моей проблемы лежит то, что я не могу перебирать массив классов и извлекать базовые данные. Вот код:

// AttackStyles.h
#ifndef ATTACKSTYLES_H
#define ATTACKSTYLES_H
#include <iostream>
#include <string>

using namespace std;

class AttackStyles
{
private:
    int styleId;
    string styleName;

public:
    // Constructors
    AttackStyles();  // default
    AttackStyles(int, string);

    // Destructor
    ~AttackStyles();

    // Mutators
    void setStyleId(int);
    void setStyleName(string);  

    // Accessors
    int getStyleId();
    string getStyleName();  

    // Functions

};
#endif


/////////////////////////////////////////////////////////
// AttackStyles.cpp
#include <iostream>
#include <string>
#include "AttackStyles.h"
using namespace std;


// Default Constructor
AttackStyles::AttackStyles()    
{}

// Overloaded Constructor
AttackStyles::AttackStyles(int i, string n)
{
    setStyleId(i);
    setStyleName(n);
}

// Destructor
AttackStyles::~AttackStyles()    
{}

// Mutator
void AttackStyles::setStyleId(int i)
{
    styleId = i;
}

void AttackStyles::setStyleName(string n)
{
    styleName = n;
}

// Accessors
int AttackStyles::getStyleId()
{
    return styleId;
}

string AttackStyles::getStyleName()
{
    return styleName;
}


//////////////////////////////////////////////
// main.cpp
#include <cstdlib>
#include <iostream>
#include <string>
#include "attackStyles.h"

using namespace std;

int main()
{
    const int STYLE_COUNT = 3;
    AttackStyles asa[STYLE_COUNT] = {AttackStyles(1, "First"), 
                                     AttackStyles(2, "Second"), 
                                     AttackStyles(3, "Third")};

    // Pointer for the array
    AttackStyles *ptrAsa = asa;

    for (int i = 0; i <= 2; i++)
    {
        cout << "Style Id:\t" << ptrAsa->getStyleId << endl;
        cout << "Style Name:\t" << ptrAsa->getStyleName << endl;
        ptrAsa++;
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

Мой вопрос: почему я получаю сообщение об ошибке:

  "a pointer to a bound function may only be used to call the function"

на обоих ptrAsa-> getStyleId и ptrAsa-> getStyleName ?

Я не могу разобраться, что с этим не так!

7
задан Ziezi 29 September 2015 в 17:12
поделиться