0

I'm terrible with pointers and need help passing an object to a library I'm writing. I'm getting the error no known conversion for argument 1 from 'LCDMenuItem*' to 'int*' when I try to compile. How do I pass a pointer to an object to a function?

LCDMenu.h

class LCDMenu {
    public:
    bool addItem(LCDMenuItem &item);
    private:
    LCDMenuItem *menuItems[MAX_ITEMS];
    uint8_t itemCount;
};

class LCDMenuItem {
    public:
    LCDMenuItem(char *name);
    bool setFunction(void (*function)(void));
    private:
    bool callFunction() const;
    void (*_function)(void);
    char *name;
};

LCDMenu.cpp

bool LCDMenu::addItem(LCDMenuItem &item) {
    menuItems[itemCount] = &item;
    ...
}

MySketch.ino

LCDMenuItem menuItem("Menu Option");
void setup() {
    menu.addItem(menuItem);
}

When trying to compile

bool addItem(LCDMenuItem *item);
     ^

no known conversion for argument 1 from 'LCDMenuItem*' to 'int*'

  • what is menuItem and where is bool addItem(LCDMenuItem *item);? – Juraj Sep 13 '19 at 16:50
  • Edited. Do you mean menuItems? its an array of LCDMenuItem's addItem() is in LCDMenu.cpp – bwoogie Sep 13 '19 at 17:03
  • menu.addItem(menuItem); menuItem. do you have the classes in that order in .h file? – Juraj Sep 13 '19 at 17:04
  • Oh, sorry. added that to MySketch.ino. I just reordered the classes putting LCDMenuItem first, didn't help. – bwoogie Sep 13 '19 at 17:11
  • and bool addItem(LCDMenuItem *item); reported by compiler is where? – Juraj Sep 13 '19 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.