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*'

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.