Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to specify object name when using .h and .CPP file

Status
Not open for further replies.

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
 

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?

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;
}
 

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....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top