Another Curious C++ Error - Illegal Left Operand

T

Tim Mierzejewski

You guys were so great with answering my first question that I've decided to
ask you yet again! Again, only the relevant code is included.

typedef unsigned int unint;
#include <iostream>

class Creature
{
public:
unint ReturnSpellPoints() {return crSpellPoints;}
void SetSpellPoints(int points) {crSpellPoints = points;}
private:
unint crSpellPoints;
};

int main()
{
Creature *Play1 = new Creature;
Play1->SetSpellPoints(10);
if (Play1->ReturnSpellPoints > 0) //Line 17
std::cout << "Select an action:\n";
return 0;
}
 
P

Patrick Kowalzick

class Creature
{
public:
unint ReturnSpellPoints() {return crSpellPoints;} [...]
};

int main()
{ [...]
if (Play1->ReturnSpellPoints > 0) //Line 17 [...]
}

while ReturnSpellPoints() is a function, you should call a function ;-)
if (Play1->ReturnSpellPoints() > 0) //Line 17, regard the brackets

Patrick
 
R

Ron Natalie

Thomas Matthews said:
The expression "Play1->ReturnSpellPoints" is the value or
address of the method. To envoke the function you need the "()".

Well actually, it's just invalid. It doesn't form a pointer to member
either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top