Unspecified error 'line does not name a type'

Hi there,

I´m interested in how working with libraries works using Arduino Uno.
Yesterday I tried to implement a library which encapsulates another one.
In Detail, i wanted to encapsulate an Object of the class LiquidCrystal_I2C as a member object in a class GUI_Display and add some functions to e.g. automatically Show a splashScreen on this LCD.

I wrote the following Header File for my library:

/***************************************************************************
 * Library GUI_Display is used to serve an Interface to a I2C LCD Display
 * 
 ***************************************************************************/

#ifndef GUI_Display_H
#define GUI_Display_H

#include "Arduino.h"
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

class GUI_Display
{
  public:
    GUI_Display(int addr, int columns, int li);
    void InitDisplay();
    void PrintWelcScreen();

  private:
    int _addr;
    int _columns;
    int _lines;
    LiquidCrystal_I2C lcd;
};




#endif

The corresponding Cpp-File looks like this:

/**************************************************************************
 * Library GUI_Display is used to serve an Interface to a I2C LCD Display
 * 
 **************************************************************************/

#include "Arduino.h"
#include "GUI_Display.h"

GUI_Display::GUI_Display(int addr, int columns, int li) : lcd(addr, columns, li)
{
  _addr = addr;
  _columns = columns;
  _lines = li;
  //lcd=new LiquidCrystal_I2C();
}

void GUI_Display::InitDisplay()
{
  this.lcd.init();
  this.lcd.backlight();
}
 
void GUI_Display::PrintWelcScreen()
{
  this.lcd.setCursor(3,0);
  this.lcd.print("Hello World");
}

In my Arduino Sketch test_cls.ino i included my lib and tried to instanciate an object of the class GUI_Display and use it:

#include "GUI_Display.h"
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

void setup() {
  // put your setup code here, to run once:
GUI_Display disp(0x27,20,4);
disp.InitDisplay();
}

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

If i try to compile the Sketch, the following error is thrown:
'line' does not Name a type; did you mean 'sinf'?

Unfortunately, the error message does not give any hint, in which line for example the error is.

It would be fantastic, if someone could provide a hint where I have to look for the Problem. Possibly, there are some other fault in the Code, too, but never Mind, I am going through step by step trying to understand all mistakes i did.

Yours, Chris

try putting

GUI_Display disp(0x27,20,4);

as global ie outside of setup() or loop().

does it compile OK then?

Hi sherzaad,

thanks for your quick Reply :slight_smile:

I already tried this before - unfortunately with no effect. The same error is thrown in this case

Best Regards,
Chris

Post the exact text of the error message you are seeing

Hi, here we go, this is the error text:

sketch\GUI_Display.cpp.cpp:1:1: error: stray '##' in program

 ##line 8 "C:\\Users\\gic\\Documents\\Arduino\\Test_class\\test_class.ino"

 ^~

sketch\GUI_Display.cpp.cpp:1:3: error: 'line' does not name a type; did you mean 'sinf'?

 ##line 8 "C:\\Users\\gic\\Documents\\Arduino\\Test_class\\test_class.ino"

   ^~~~

   sinf

test_class:0:1: error: 'line' does not name a type; did you mean 'sinf'?

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:23:0,

                 from C:\Users\gic\Documents\Arduino\Test_class\test_class.ino:6:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:153:61: error: 'size_t' has not been declared

 extern void *bsearch(const void *__key, const void *__base, size_t __nmemb,

                                                             ^~~~~~

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:154:8: error: 'size_t' has not been declared

        size_t __size, int (*__compar)(const void *, const void *));

        ^~~~~~

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:185:33: error: 'size_t' has not been declared

 extern void qsort(void *__base, size_t __nmemb, size_t __size,

                                 ^~~~~~

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:185:49: error: 'size_t' has not been declared

 extern void qsort(void *__base, size_t __nmemb, size_t __size,

                                                 ^~~~~~

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:300:21: error: 'size_t' was not declared in this scope

 extern void *malloc(size_t __size) __ATTR_MALLOC__;

                     ^~~~~~

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdlib.h:300:21: note: suggested alternative: '__size_t'

 extern void *malloc(size_t __size) __ATTR_MALLOC__;

                     ^~~~~~

                     __size_t

[….]

test_class:51:9: error: request for member 'lcd' in '(GUI_Display*)this', which is of pointer type 'GUI_Display*' (maybe you meant to use '->' ?)

exit status 1
'line' does not name a type; did you mean 'sinf'?

At the Moment only the first lines are relevant, the further lines report Errors I will check in a second step. I left out some of These lines due to the limited message size in this community.

Best regards, Chris

Which version of the Arduino IDE are you using?

Hi pert,

I am currently using Arduino IDE v1.8.11

Best Regards, Chris

This is very strange. The Arduino IDE does some preprocessing on the .ino files of the sketch to turn them into valid C++ before compiling. It adds #line directives so that error and warning messages will still match your .ino file. It looks like it is messing up one of these inserted #line directives by adding an extra #. But the strangest thing is that it appears to be adding the #line directive to a .cpp file. Sketch preprocessing is only done on .ino files, so the Arduino IDE should never touch a .cpp file.

I tried the code you posted and I couldn't reproduce the problem. Please put your entire Test_class sketch folder in a .zip file and attach it to a reply here so I can be sure I'm reproducing your setup exactly. If you click the "Reply" button, you'll see an "Attachments and other settings" link that will allow you to make the attachment.

Thanks for your explanations and your assistance :slight_smile:

I´ve attached my Test_class Folder to this post.

Test_class.zip (1.47 KB)

OK, now the problem is clear. The sketch folder name must match the filename of the primary .ino file. Your sketch folder name is Test_class, but your .ino name is test_class. There is a bug in the Arduino IDE that causes the wrong file to be preprocessed when there is a case mismatch between the sketch folder and filename and the IDE is running on a filename case-insensitive OS like Windows:

The solution is to either rename the folder to test_class, or the file to Test_class.ino.

Yeah, thank you so much! I will try this evening :slight_smile: