Another Curious C++ Error - Illegal Left Operand

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mierzejewski

    Another Curious C++ Error - Illegal Left Operand

    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 ReturnSpellPoin ts() {return crSpellPoints;}
    void SetSpellPoints( int points) {crSpellPoints = points;}
    private:
    unint crSpellPoints;
    };

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

    --
    C:\...filename( 17) : error C2296: '>' : illegal, left operand has type
    'unsigned int (__thiscall Creature::*)(vo id)'
    --
    What's wrong with the operand? And what's __thiscall?

    Thanks,
    Tim M.


  • Patrick Kowalzick

    #2
    Re: Another Curious C++ Error - Illegal Left Operand

    > class Creature[color=blue]
    > {
    > public:
    > unint ReturnSpellPoin ts() {return crSpellPoints;}[/color]
    [...][color=blue]
    > };
    >
    > int main()
    > {[/color]
    [...][color=blue]
    > if (Play1->ReturnSpellPoi nts > 0) //Line 17[/color]
    [...][color=blue]
    > }[/color]

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

    Patrick


    Comment

    • Ron Natalie

      #3
      Re: Another Curious C++ Error - Illegal Left Operand


      "Thomas Matthews" <thomas_matthew s@sbcglobal.net > wrote in message news:3EFA0A95.2 060201@sbcgloba l.net...
      [color=blue]
      > The expression "Play1->ReturnSpellPoi nts" is the value or
      > address of the method. To envoke the function you need the "()".[/color]

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



      Comment

      Working...