Nov 2, 2018 #1 N NewbeeAVR Junior Member level 2 Joined Dec 2, 2017 Messages 21 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 195 I have LCD class and a object lcd as follows. Code: class LCD{ public: ... ... }lcd; How to specify lcd object with two files lcd.h and lcd.cpp
I have LCD class and a object lcd as follows. Code: class LCD{ public: ... ... }lcd; How to specify lcd object with two files lcd.h and lcd.cpp
Nov 4, 2018 #2 AskSensors Junior Member level 1 Joined Oct 31, 2018 Messages 18 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Location Paris Activity points 112 Hello, I don't see what you mean. Could you specify : - The IDE you are using? - Where are you putting the main code ? is in a main file?
Hello, I don't see what you mean. Could you specify : - The IDE you are using? - Where are you putting the main code ? is in a main file?
Nov 4, 2018 #3 N NewbeeAVR Junior Member level 2 Joined Dec 2, 2017 Messages 21 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 195 AskSensors said: Hello, I don't see what you mean. Could you specify : - The IDE you are using? - Where are you putting the main code ? is in a main file? Click to expand... I am using DevC++. I need to write lcd.h Code: class LCD{ void display(char); }; lcd.cpp Code: void LCD :: display(char c){ //my code } Then in main.cpp Code: #include <iostream> using namespace std; int main(){ LCD lcd; // Is any way to not specify hear but anywhere else in lcd.h or lcd.cpp lcd.display(A); return 0; }
AskSensors said: Hello, I don't see what you mean. Could you specify : - The IDE you are using? - Where are you putting the main code ? is in a main file? Click to expand... I am using DevC++. I need to write lcd.h Code: class LCD{ void display(char); }; lcd.cpp Code: void LCD :: display(char c){ //my code } Then in main.cpp Code: #include <iostream> using namespace std; int main(){ LCD lcd; // Is any way to not specify hear but anywhere else in lcd.h or lcd.cpp lcd.display(A); return 0; }
Nov 19, 2018 #4 P pete16 Junior Member level 1 Joined Jul 7, 2017 Messages 16 Helped 1 Reputation 2 Reaction score 2 Trophy points 3 Location Chicago Activity points 141 You are creating an instance of the object in your main.cpp. It will work you just need to include the header file in your main.cpp - #include "lcd.h" Here's how I use my LCD class: LCD.h: void SendCharacter(unsigned char character); LCD.cpp: void LCDInfo::SendCharacter(unsigned char character) { //My Code here } then in main.cpp: LCDInfo *objLCD; objLCD = new LCDInfo(); //I use a pointer //Call some functions: objLCD->InitLCD(); objLCD->SendCharacter(chCurrDisplayCharacter); etc....
You are creating an instance of the object in your main.cpp. It will work you just need to include the header file in your main.cpp - #include "lcd.h" Here's how I use my LCD class: LCD.h: void SendCharacter(unsigned char character); LCD.cpp: void LCDInfo::SendCharacter(unsigned char character) { //My Code here } then in main.cpp: LCDInfo *objLCD; objLCD = new LCDInfo(); //I use a pointer //Call some functions: objLCD->InitLCD(); objLCD->SendCharacter(chCurrDisplayCharacter); etc....