Error: 'classname' does not name a type Arduino 2

I am trying to create a simple class in Arduino 2. But getting some weird error class name does not name a type. What could be the issue?

Header File

#ifndef classEeprom_H
#define classEeprom_H

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

class clsEeprom {
public:
  clsEeprom();
  void start();
  
private:
  const uint16_t EEPROM_SIZE = 512;
};
#endif

cpp file

#include "Arduino.h"
#include "classEeprom.h"


clsEeprom::clsEeprom(void) {
  EEPROM.begin(EEPROM_SIZE);
  Serial.println("EEprom Class Init");
}

void clsEeprom::start() {

}

and the error is

clsEeprom.cpp:4:1: error: 'clsEeprom' does not name a type

exit status 1

Compilation error: exit status 1

What could be the issue?

It seems that The cpp is called clsEeprom.cpp and the .h classEeprom.h

Call them the same way

classEeprom.cpp
classEeprom.h

(Or make sure you #include the right file)

If it does not work please give us file names as well as the .ino content and anything else that is in the same sketch directory

Thanks. Thats a good catch. But my cpp file name is classEeprom.cpp i am wondering why it refers as clsEeprom.cpp. even i checked in folder and there is no file in that name.

➜ can you provide that?

There are lot of files(classes) in that directory. i never mind sharing that but dont know if it helps in any way. shall i send screen shot?

You named it that, included it (added), then renamed it, so it still refers to the old name

Then the issue is likely somewhere else in those files and the .ino

Screen shot won’t help

You could test with a new directory with just that class and a simple sketch creating a couple instances and see if you get the same issue.

Might be a library that you have that comes in the way if you include with <> instead of “”

No I didn't renamed. I have deleted and created new class only.

there is no magic, your project knows your cpp file by clsEeprom name

What IDE are you using let’s start with that

I changed to "" also it wont work. Earlier also i got similar issue but if i copy sample code from internet it works fine but if i typed the same thing when creating class it won't work. I know this is looking funny :slight_smile: but honestly this is the case. So i just thought of posting in forum to know if any other got similar issue.

and why it is referring clsEeprom how do i change this to classEeprom? where the compile files get stored? any idea pls

Now i have deleted both the h and cpp and dereferenced from main ino. compiled once. Then created new file classEeprom.h and classEeprom.cpp , copy the content from this forum to that file. reference again in main ino, compiles perfectly fine. Seems some bug with compiling in IDE.

I am using
Version: 2.0.0
Date: 2022-09-14T07:06:37.759Z
CLI Version: 0.27.1 [a900cfb2]

Copyright © 2022 Arduino SA

Should have started with that lol

I for one am confused as to where you have ended up and which code you are compiling

Please post the .h, .cc and .ino files in a new post here

:slight_smile: if you are looking to recreate the error, create class files and type everything instead of copying and try to compile to see if you are getting same error. i am using esp32 FYI

Search in your computer for the file clsEeprom.cpp

Without the original .ino and all the files from the same directory it’s hard to tell

It might have been a quirk from IDE 2.0 but I doubt it would be inventing file names…

main file

#include "classEeprom.h"

clsEeprom* myEeprom;



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

void loop() {
}

classEeprom.h file

#ifndef classEeprom_H
#define classEeprom_H

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

class clsEeprom {
public:
  clsEeprom();
  void start();
  
private:
  const uint16_t EEPROM_SIZE = 512;
};
#endif

classEeprom.cpp file

#include "Arduino.h"
#include "classEeprom.h"


clsEeprom::clsEeprom(void) {
  EEPROM.begin(EEPROM_SIZE);
  Serial.println("EEprom Class Init");
}

void clsEeprom::start() {

}

Do not copy paste, type the class file contents and try to compile

I feel the same. Anyway let me search the clsEeprom and let you know if i can find it.

Yes i got the file somewhere in temp

C:\Users\AmalDev\AppData\Local\Temp\arduino-language-server2462080602\sketch

file content as below:

#line 1 "C:\\Users\\AmalDev\\Documents\\Arduino\\Smart_walking_stick_project-v1\\clsEeprom.cpp"

I didn't understood anything :frowning: I have exceeded reply quota. cant post new reply. Still i am not able to reply as same quota error. I will post more information tomorrow.

it created it for you looks like