Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i solve this "chicken vs egg" declaration issue?

New with C++ but been coding a lot of ObjC back in the day. So i thought i was smart trying to solve a cross reference issue with the old delegate pattern used widely in ObjC but only managed to move the issue it to another file 😂.

Im trying to reach the invoker of the file by passing it as a reference, conforming to a "interface".

#pragma once

#include <libUI.h>
#include <Arduino.h>

class PeripheralDelegate {
public:
    virtual void pushViewController(PeripheralViewController* vc) = 0;
    virtual void popLastViewController() = 0;
};

class PeripheralViewController: public ViewController {
private:
    PeripheralDelegate* mDelegate;
public:
    PeripheralViewController(): ViewController(), mDelegate() {}
    PeripheralViewController(String id, Rect frame, PeripheralDelegate* delegate): ViewController(id, frame), mDelegate(delegate) {}
    virtual ~PeripheralViewController() {}
    virtual void encoderValueChanged(int newVal, int oldVal) = 0;
    virtual void encoderSwitchPressed() = 0;
    virtual void backButtonPressed() = 0;
    virtual void firstButtonPressed() = 0;
    virtual void secondButtonPressed() = 0;
};

Also, all kind of feedback on the code is much appriciated!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can predeclare PeripheralViewController and then you can use a pointer to it:

class PeripheralViewController;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading