Calling lcd.print() in derived classes of an lcd menu class

I have looked through out this forum and can not find find anything about using lcd.print() in a derived class of a menu class that im working on. I keep getting errors about the lcd instance not having a type. does anyone have a quick idea of what Im missing?

does anyone have a quick idea of what Im missing?

Yes. Some code for us to look at.

can not find find anything about using lcd.print() in a derived class of a menu class that im working on.

Which menu class? What does it derive from? Which class are you working on?

I keep getting errors about the lcd instance not having a type.

What is "the lcd instance" an instance of? Where are you using (or trying to use) this instance? How is that code informed of "the lcd instance"?

We really do need to see your code. All of it. Header files, source files AND sketch.

Im sorry about the vagueness of the issue, can you tell this is my first post.... im not at home so i dont have the code. But im using the LiquidCrystal lib. and creating an instance in the setup loop. I have a menu class that I have written in a header to create an instance of each submenu. Each instance has strings in the constructor to display on the lcd screen as menu options. as soo as i try to lcd.print() the strings to the screen the program gives me lcd object has no type, if i dont call any liquidCrystal functions the program compiles fine. Perhaps Im not telling the compiler where to find the LiquidCrystal object?

If you really need to to see the code ill post it tomorrow

But im using the LiquidCrystal lib. and creating an instance in the setup loop.

The setup() function, you mean? An instance created in a function is local to that function. You need to create a global instance.

Frankly I don't think a menu class should be derived from LCD. A menu is a data structure, items, their corresponding functions, etc. It shares no similarity with LCD class, which is a display class for manipulating outputs, very much similar to serial class and could have been derived from it but unfortunately not.

If I were to write a menu class I would make it into a data structure and maybe having a link to an lcd instance for its output.

very much similar to serial class and could have been derived from it but unfortunately not.

Both LiquidCrystal and HardwareSerial derive from Print, which, in my mind, is the better derivation path.

liudr:
Frankly I don’t think a menu class should be derived from LCD. A menu is a data structure, items, their corresponding functions, etc. It shares no similarity with LCD class, which is a display class for manipulating outputs, very much similar to serial class and could have been derived from it but unfortunately not.

If I were to write a menu class I would make it into a data structure and maybe having a link to an lcd instance for its output.

This is exactly what im trying to do. i just need the link to the lcd instance

create a global instance of lcd? ill try it when i get home. I thought i already tried it but i may have entered something wrong.

PaulS:

very much similar to serial class and could have been derived from it but unfortunately not.

Both LiquidCrystal and HardwareSerial derive from Print, which, in my mind, is the better derivation path.

I didn't know that :blush:

I will look into the print class. BTW, I'm looking for code for println to see if it outputs \n or \n\r or \r or \r\n. Any idea?

This is exactly what im trying to do. i just need the link to the lcd instance

Then you just need a member pointer in the class like this: LiquidCrystal * lcd;

Then in code BEFORE setup you do: LiquidCrystal lcd(9,8,7,6,5,4); menu main_menu();

Then in setup() you do: main_menu.lcd=&lcd;

What you were doing was probably not right.

liudr:

PaulS:

very much similar to serial class and could have been derived from it but unfortunately not.

Both LiquidCrystal and HardwareSerial derive from Print, which, in my mind, is the better derivation path.

I didn't know that :blush:

I will look into the print class. BTW, I'm looking for code for println to see if it outputs \n or \n\r or \r or \r\n. Any idea?

This is exactly what im trying to do. i just need the link to the lcd instance

Then you just need a member pointer in the class like this: LiquidCrystal * lcd;

Then in code BEFORE setup you do: LiquidCrystal lcd(9,8,7,6,5,4); menu main_menu();

Then in setup() you do: main_menu.lcd=&lcd;

What you were doing was probably not right.

Awsome... I tried using a pointer last night but it didnt look any thing like yours. Thanks for the help, that looks like what i needed.

I will look into the print class. BTW, I'm looking for code for println to see if it outputs \n or \n\r or \r or \r\n. Any idea?

Sure. Look at the Print.cpp file. My guess is that the actual output is OS dependent. But, that is strictly a guess.

If you didn't get it to work you can look at my library:

http://liudr.wordpress.com/libraries/phi_prompt/

It is not a class since I don't think a class is needed for my functions but I did create a struct to store information for various elements and store an lcd pointer in the library.

Paul, you're legend! I am still finding my way through the maze of all the files arduino IDE compiles. So:

void Print::println(void) { print('\r'); print('\n'); }

It makes no difference to me as long as it is not just \r but always nice to know exactly what happens. I get an uneasy feeling if I don't. XD

Thanks every one for your help. I couldnt get the pointer working, but, i did get it working. I created an instance of LiquidCrystal in my .cpp, then inserted lcd.begin(24,2) into my menu constructor