# Error when compiling “Does not name a type”

I want to inherit my own class from LiquidCrystal that creates some custom characters during initialization. Here's the code I've written so far:

MyProject.ino

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

MyLiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Welcome");
}

void loop()
{
}


MyLiquidCrystal.h

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

namespace MyProject
{
class MyLiquidCrystal: public LiquidCrystal
{
private:
void createCustomChars()
{
byte smiley[8] = { B00000, B10001, B00000, B00000, B10001, B01110, B00000 };
this.createChar(0, smiley);
}

public:
MyLiquidCrystal(uint8_t rs,  uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
: LiquidCrystal(rs, enable, d0, d1, d2, d3)
{
createCustomChars();
}
};
};


I'm getting the following error at line MyLiquidCrystal lcd(8, 9, 4, 5, 6, 7);:

MyProject:5: error: 'MyLiquidCrystal' does not name a type


I've been googling for a while now but couldn't figure out what's going on. Any help would be appreciated!

• It's not what you asked, but if the Arduino language is anything like C++, you should only have method declarations, not method definitions, in a .h file. – The Photon Jun 16 '13 at 14:14
• Why would you use this namespace stuff for embedded? How many dozens of developers are working on this? How many megabytes is the executable? – Kaz Jun 17 '13 at 2:53
• I saw the using of namespaces in a tutorial. I know what are they good for (I'm a C# developer). Only embedded development is new to me. – papaiatis Jun 18 '13 at 11:42

Try removing namespace MyProject from the header file. That's not required and means that it's not finding the class located outside the namespace. Alternatively you can use the new namespace prefix in your main project as another answer suggests.

• Alternatively, in MyProject, change your type reference to MyProject::MyLiquidCrystal, or add a line using namespace MyProject;, but namespaces for Arduino projects are likely to be overkill. – microtherion Jun 16 '13 at 13:13
• In that case, using a namespace is overkill indeed. However, it is untrue that using namespace in header is bad practice. That's exactly how they should be used (for project that warrants their use). – abey Jun 16 '13 at 13:14
• -1 for stating that a namespace mentioned in a header is bad practice! – Wouter van Ooijen Jun 16 '13 at 17:29
• @WoutervanOoijen, true it was getting late... Have revised it. – PeterJ Jun 17 '13 at 1:23

Since your class MyLiquidCrystal is declared inside a namespace (MyProject), you need to use the full type name to use it outside of that namespace. In your case, you should replace:

MyLiquidCrystal lcd(8, 9, 4, 5, 6, 7);


by

MyProject::MyLiquidCrystal lcd(8, 9, 4, 5, 6, 7);


Alternatively, you could add the following line at the top of your sketch:

using namespace MyProject;


This will tell the compiler that the whole content of MyProject namespace should be imported to the global namespace, which will allow direct access to its content.

• This is also a solution indeed! However, PeterJ was faster thus the points go for him. Thank you for your help too! :) – papaiatis Jun 16 '13 at 16:21
• Feel free to move the "accept" to whichever you ultimately judge is the better answer... – Brian Drummond Jun 16 '13 at 18:35