Search code examples
c++most-vexing-parse

Expression must have a class type Error 153


This code for a 7segment display on an mbed, i am getting the error

Error: Expression must have class type in "main.cpp", Line: 44, Col: 6

which is the line of seg_7.write(livewrite);

I have tried different syntaxes and this seems to be the right solution but it doesnt work? Also when i change write in seg_7.write(livewrite); to anything else it gives the same error leading me to think its that syntax.

-------Library--------------

    class ShiftReg {
    public :

        ShiftReg();    
        ~ShiftReg();
        void write(int data);

    private :
        DigitalOut *clkout;
        DigitalOut *dataout;
        DigitalOut *latchout;
};

ShiftReg seg_7();    

void refresh()
{
    char livewrite = hex_nums[lives];
    seg_7.write(livewrite);
    lcd.clear();
    drawsprite(hx,hy,HeroX,HeroY,hero);
    lcd.refresh();

}

Solution

  • As you have declared it:

    ShiftReg seg_7();    
    

    seg_7 is the prototype of a function taking no arguments and returning ShiftReg, not an object of the type ShiftReg. There is no need for the brackets, just:

    ShiftReg seg_7;
    

    Will fix the problem.