"error: 'A' cannot be overloaded", but there isn't any overload in the code

Kroltan

I've just got an Arduino and started learning C++. I decided to start by implementing a simple "car dodge" game, present in those very old "9999 in 1" handhelds using a LCD and pushbuttons. However I encountered a very strange issue with the code.

The compiler believes I'm trying to override setUp and tearDown, but I can't see where this is happening. There is literally no further instances than the original function definitions, yet this is what happens when I try to compile (using Stino for Sublime Text, if that's relevant):

Compiling lcd...
Creating C:\Users\Leonardo\Documents\Arduino_Build\lcd\lcd.ino.cpp.o...
C:\Users\Leonardo\Documents\Arduino_Build\lcd\lcd.ino.cpp:31: error: 'virtual void Scene::setUp(LiquidCrystal)' cannot be overloaded
C:\Users\Leonardo\Documents\Arduino_Build\lcd\lcd.ino.cpp:25: error: with 'virtual void Scene::setUp(LiquidCrystal)'
C:\Users\Leonardo\Documents\Arduino_Build\lcd\lcd.ino.cpp:32: error: 'virtual void Scene::tearDown(LiquidCrystal)' cannot be overloaded
C:\Users\Leonardo\Documents\Arduino_Build\lcd\lcd.ino.cpp:26: error: with 'virtual void Scene::tearDown(LiquidCrystal)'
[Stino - Error 1]

This is the "game" source file, lcd.ino, which has nothing of game yet:

#include "LiquidCrystal.h"

#define LEFT_BUTTON_PIN 8
#define RIGHT_BUTTON_PIN 7

#define LEFT_PRESSED B10
#define RIGHT_PRESSED B01

#define STATE_SPLASH 0
#define STATE_PLAY 1
#define STATE_SCORE 2

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);


class Scene {
    public:
    virtual void loop(byte input, LiquidCrystal lcd) {}
    virtual void setUp(LiquidCrystal lcd) {}
    virtual void tearDown(LiquidCrystal lcd) {}
};

class Splash : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("Welcome to CAR DODGE");
        lcd.print("Press LEFT to start!");
    }
};

class Game : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("HI");
    }
};

class Score : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("HI");
    }
};


byte currentMode = STATE_SPLASH;
Scene *gameModes[] = {new Splash(), new Game(), new Score()};

byte getInput() {
    bool leftSample1 = digitalRead(LEFT_BUTTON_PIN);
    bool rightSample1 = digitalRead(RIGHT_BUTTON_PIN);
    Serial.print(leftSample1);
    Serial.print(" ");
    Serial.println(rightSample1);
}

void changeGameMode(byte next) {
    gameModes[currentMode]->tearDown(lcd);
    gameModes[next]->setUp(lcd);
    currentMode = next;
}

void setup() {
    Serial.begin(9600);

    pinMode(LEFT_BUTTON_PIN, INPUT);
    pinMode(RIGHT_BUTTON_PIN, INPUT);
    lcd.begin(20, 4);

    changeGameMode(STATE_SPLASH);
}

void loop() {
    byte input = getInput();
    gameModes[currentMode]->loop(input, lcd);
    delay(150);
}

EDIT: lcd.ino.cpp contents, which is generated by the Arduino build tools:

#include <Arduino.h>
#include "LiquidCrystal.h"

#define LEFT_BUTTON_PIN 8
#define RIGHT_BUTTON_PIN 7

#define LEFT_PRESSED B10
#define RIGHT_PRESSED B01

#define STATE_SPLASH 0
#define STATE_PLAY 1
#define STATE_SCORE 2

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);


class Scene {
    public:

virtual void setUp(LiquidCrystal lcd);
virtual void tearDown(LiquidCrystal lcd);
byte getInput();
void changeGameMode(byte next);

virtual void loop(byte input, LiquidCrystal lcd) {}
    virtual void setUp(LiquidCrystal lcd) {}
    virtual void tearDown(LiquidCrystal lcd) {}
};

class Splash : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("Welcome to CAR DODGE");
        lcd.print("Press LEFT to start!");
    }
};

class Game : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("HI");
    }
};

class Score : public Scene {
    public: void loop(byte input, LiquidCrystal lcd) {
        lcd.print("HI");
    }
};


byte currentMode = STATE_SPLASH;
Scene *gameModes[] = {new Splash(), new Game(), new Score()};

byte getInput() {
    bool leftSample1 = digitalRead(LEFT_BUTTON_PIN);
    bool rightSample1 = digitalRead(RIGHT_BUTTON_PIN);
    Serial.print(leftSample1);
    Serial.print(" ");
    Serial.println(rightSample1);
}

void changeGameMode(byte next) {
    gameModes[currentMode]->tearDown(lcd);
    gameModes[next]->setUp(lcd);
    currentMode = next;
}

void setup() {
    Serial.begin(9600);

    pinMode(LEFT_BUTTON_PIN, INPUT);
    pinMode(RIGHT_BUTTON_PIN, INPUT);
    lcd.begin(20, 4);

    changeGameMode(STATE_SPLASH);
}

void loop() {
    byte input = getInput();
    gameModes[currentMode]->loop(input, lcd);
    delay(150);
}

What am I missing here?

Ilyas

Answer might be a little late but;

It appears the Arduino IDE doesn't like member functions being declared in the class definition.

Just to be clear:

class example {
    public:
           void function(){ /*code not here*/ };  
    private:
            int variable;
};

void example::function(){
    //code here
}  

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

"error: 'A' cannot be overloaded", but there isn't any overload in the code

From Dev

Eclipse deployment code isn't taking into consideration any changes

From Dev

The code isn't efficient

From Dev

Why isn't an overload provided in standard library functions with iterator parameters?

From Dev

Trying to use a link delay, but any code I try isn't working

From Dev

My code isn't giving the user's the correct feedback. Any ideas how to fix this?

From Dev

Trying to use a link delay, but any code I try isn't working

From Java

Why isn't this code unreachable?

From Dev

Code isn't jumping correctly

From Dev

My code isn't executing

From Dev

Why isn't the XSL displaying any data

From Dev

Why karma isn't executing any tests?

From Dev

XDocument isn't returning any values

From Dev

Why isn't [SomeStruct] convertible to [Any]?

From Dev

WebAudio isn't giving any audio output

From Dev

Cypher Query isn't returning any Nodes

From Dev

Why isn't [SomeStruct] convertible to [Any]?

From Dev

Any mapping in vimrc with Alt isn't working

From Dev

Is token verification required if there isn't any registration?

From Dev

Why jQuery code isn't working?

From Dev

Why isn't this code executing synchronously?

From Dev

Why isn't compiler optimizing away this code

From Dev

jquery code for click event isn't working

From Java

Code isn't swapping cases as I expect it to

From Dev

My code isn't enough to show a triangle

From Dev

Why isn't this JavaScript code executing?

From Dev

Code isn't calculating decimal places

From Dev

Approximating Pi - Why isn't this code working?

From Dev

Why isn't selectedIndex working in this code?

Related Related

HotTag

Archive