ISO C++ forbids declaration of 'Radar' with no type

Hello. I'm trying to understand all of this OOP stuff but i stumbled upon a weird problem. I was trying to offload a lengthy animation along with image data to a custom class in a separate file. I debugged it all but now I'm stuck with this error:
C:\Users\Admin\Documents\Arduino\OOP_Test\src\Nijika.cpp:2215:1: error: ISO C++ forbids declaration of 'Radar' with no type [-fpermissive]
2215 | Nijika::Radar(){
| ^~~~~~
C:\Users\Admin\Documents\Arduino\OOP_Test\src\Nijika.cpp:2215:1: error: no declaration matches 'int Nijika::Radar()'
In file included from C:\Users\Admin\Documents\Arduino\OOP_Test\src\Nijika.cpp:1:
C:\Users\Admin\Documents\Arduino\OOP_Test/Nijika.h:6:30: note: candidate is: 'void Nijika::Radar()'
6 | void Radar();
| ^~~~~
C:\Users\Admin\Documents\Arduino\OOP_Test/Nijika.h:4:23: note: 'class Nijika' defined here
4 | class Nijika{
| ^~~~~~

exit status 1

Compilation error: ISO C++ forbids declaration of 'Radar' with no type [-fpermissive]

However, i do have void before Nijika::Radar(); Here's the code:
OOP_Test.ino:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <Nijika.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//int a=0;
int x=0;
int y=0;

Nijika Nijika;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Here's a lot of image data

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));}
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Starting...");
  display.display();
  delay(1000);
  display.setCursor(0, 16);
  display.println("RAM... OK");
  display.display();
  delay(200);
  display.setCursor(0, 32);
  display.println("Graphics... OTVAL");
  display.display();
  delay(300);
  display.setCursor(0, 48);
  display.println("All systems nominal");
  display.display();
  delay(500);
display.clearDisplay();
display.drawBitmap(0,0, image_data_binbows, 128, 64, 1);
display.display();
delay(100);
display.clearDisplay();
  display.invertDisplay(true);
  delay(500);
  display.invertDisplay(false);
  delay(500);
  display.drawBitmap(0,0, image_data_app, 128, 58, 1);
  display.display();
  delay(5000);
  display.clearDisplay();
  
}

void loop() {
  // put your main code here, to run repeatedly:
Nijika.Radar();
}

Nijika.h:

#pragma once
#include <Arduino.h>

		class Nijika{
		public:
			void Radar();
			
		private:
		};

Nijika.cpp:

#include <Nijika.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//Even more image data

void Nijika::Radar(){
	display.drawBitmap(19,0, image_data_1, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_2, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_3, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_4, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_5, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_6, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_7, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_8, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_9, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_10, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_11, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_12, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_13, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_14, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_15, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_16, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
	display.drawBitmap(19,0, image_data_17, 89, 64, 1);
	display.display();
	delay(120);
	display.clearDisplay();
}

Why is my void invisible to a compiler? BTW It's for ESP32 in case it's really compiler problem

Start with not giving the instance the same name as the class. Really bad idea.

So can we see line 2215 ?

BTW it looks like a method used without prior declaration. This results in compiler assuming your method is int XXX (void). But your actual method is void XXX (void)

Post full code

line 2215 is a part of a c array, compiler showed line 2224 while saying it's 2215. Full code is here

You declare display in both OOP_Test.ino and Nijika.cpp. That doesn't work. The linker balks with a "multiple definition of 'display'" error, and properly so.

You declare an instance of Nijika in both OOP_Test.ino and Nijika.cpp. That doesn't work. The linker balks again, with a "multiple definition of 'Nijika'" error.

With display reduced to an extern declaration in Nijika.cpp and the declaration of the instance of Nijika in Nijika.cpp removed, you sketch compiles just fine. No complaints from the compiler about anything, let alone "ISO C++ forbids declaration of 'Radar' with no type". I never saw that error, even before fixing the duplicate declarations.

Either you're not showing us the same code that produces the error you claim to be seeing, or you're doing something very odd in your compilation process. All I did was stick Nijika.h and the complete Nijika.cpp in a Nijikia directory under libraries (given that you're using #include <> rather than #include ""), and compile OOP_Test for an ESP32.

1 Like

Please, show me the code that compiled, i tried applying all your fixes but to no avail. I'm not really familiar with externs yet

Better yet, why don't you show us an MRE of your code? This is the smallest complete code that reproduces the problem at hand. You've already caused confusion by posting a snippet of one code and the error message from a different, much larger code.

Nijika.ino
Nijika.h:

#pragma once
#include <Arduino.h>

		Class Nijika{
		public:
			void Radar();
			
		private:
		};

Nijika.cpp

You apparently missed the word "smallest" in my request:

The "M" in MRE stands for Minimal! Get rid of the thousands of line of unneeded clutter and cut it done to only what's needed to demonstrate the problem. If arrays are really required in the demo, make them of minimal size. The demo doesn't need to actually work like your final project because your problem is a compiler error. Then post it all here inline, not links.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.