A pointer to a bound function may only be used to call the function
Solution 1
You are missing ()
around the function calls. It should be ptrAsa->getStyleId()
.
Solution 2
You are missing parenthesis on both calls, it should be
ptrAsa->getStyleId()
to call the function.
ptrAsa->getStyleId
is used to refer to a member value / attribute.
Solution 3
You need to invoke the function, not merely reference it:
std::cout << "Style Id:\t" << ptrAsa->getStyleId() << "\n";
std::cout << "Style Name:\t" << ptrAsa->getStyleName() << "\n";
Solution 4
You are Forgot to put () in last in Your Function(ptrAsa->getStyleId ) Calling with arrow operator.

Kardsen
Updated on April 03, 2021Comments
-
Kardsen about 2 years
I'm working on a homework assignment for my C++ class and have ran across a problem that I cannot figure out what I am doing wrong.
Just to note, the separation of the files is necessary and I realize this would be much easier if I just made a structure
AttackStyles
inside themain
and forgo the additional class file altogether.The base of my problem is that I cannot seem to be able to loop through an array of classes and pull out base data. Here is the code:
// 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; }
My question is why do I get the error:
"a pointer to a bound function may only be used to call the function"
on both
ptrAsa->getStyleId
andptrAsa->getStyleName
?I cannot figure out what is wrong with this!
-
Kardsen over 11 yearsOMG! I'm just gonna crawl back into my hole now. Extremely sorry for the stupid question lol.