I am working on homework for my C ++ class and have run into a problem that cannot understand what I'm doing wrong.
Just note that file separation is necessary, and I understand that it would be much easier if I just created the structure AttackStylesinside mainand generally abandoned the extra class file.
At the heart of my problem is that I cannot skip the class loop and pull out the underlying data. Here is the code:
#ifndef ATTACKSTYLES_H
#define ATTACKSTYLES_H
#include <iostream>
#include <string>
using namespace std;
class AttackStyles
{
private:
int styleId;
string styleName;
public:
AttackStyles();
AttackStyles(int, string);
~AttackStyles();
void setStyleId(int);
void setStyleName(string);
int getStyleId();
string getStyleName();
};
#endif
#include <iostream>
#include <string>
#include "AttackStyles.h"
using namespace std;
AttackStyles::AttackStyles()
{}
AttackStyles::AttackStyles(int i, string n)
{
setStyleId(i);
setStyleName(n);
}
AttackStyles::~AttackStyles()
{}
void AttackStyles::setStyleId(int i)
{
styleId = i;
}
void AttackStyles::setStyleName(string n)
{
styleName = n;
}
int AttackStyles::getStyleId()
{
return styleId;
}
string AttackStyles::getStyleName()
{
return styleName;
}
#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")};
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;
}
My question is: why am I getting the error:
"a pointer to a bound function may only be used to call the function"
on ptrAsa->getStyleIdand ptrAsa->getStyleName?
I can’t understand what’s wrong with that!
source
share