How to create header files in C++

Publisher:WeaselLatest update time:2015-05-08 Source: 51heiKeywords:C++ Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Create a header file. (Without parameters)

cpp is linked to the header file through the class name + :: + function name. Note that it must be the class name + ::!
The function code is placed in the corresponding function name under cpp, while the header file only contains the function name, which is only responsible for providing mapping.
animal. cpp
#include "animal.h"
#include
animal::animal()
{
   cout<<"hello"< }
void animal::eat ()
{
   cout<<"shift"< }

animal.h
//The header file only writes the function name and provides the link address. 
#ifndef ANIMAL_H_H
#define ANIMAL_H_H
class animal
{
  public:
  animal();

void eat();
};
#endif

-------------------------------------------------- ----------------------------------

If you don't create a header file, you have to write such a long code that is not very readable #include

class animal
{
public:
animal()
{
cout<<"animal construct"<
}
~animal()
{
cout<<"construct animal"<
}
virtual void breath()  
{
cout<<"bubble2"<
}
void eat(); //Put the main function outside the class
};
class fish:public animal 
{
public:
fish()
{
 
}
~fish()
 
}
 void breath()
{   
 
}
};
void animal::eat() // Function type, which class it belongs to. Put the implementation of a function outside the class.
{
 
}
 
void main()
{
 
}
Keywords:C++ Reference address:How to create header files in C++

Previous article:C++ subclass overrides base class and virtual processing
Next article:Examples of using SWITCH-CASE BREAK statement in C++

Recommended ReadingLatest update time:2024-11-16 18:01

Why should the P0~P3 ports of the 89C51 microcontroller be set to 1 when inputting?
The P0~P3 ports of the 89C51 microcontroller are not standard bidirectional ports, but quasi-bidirectional ports. You can read this paragraph in conjunction with the structure diagram of port P0 . Writing 1 to the port is writing 1 to the latch. That is to let its port output FF, why, it is like this, write 1 to the
[Microcontroller]
Why should the P0~P3 ports of the 89C51 microcontroller be set to 1 when inputting?
ARM11 S3C6410 Hardware Floating Point (VFP) Implementation
When debugging a code, the code can be compiled successfully. However, it cannot be executed. After searching for a long time, I found that it was a floating point problem. Since 6410 supports hardware floating point, I searched for a long time before I figured out how to use hardware floating point. 1. Select
[Microcontroller]
ARM C/C++ Compiler
The ARM C/C++ compiler can be used in UNIX and Windows/MS-DOS environments. The ARM C++ compiler complies with the international standard for C++ ISO/IEC 14822:1998. The ARM C/C++ compiler can compile C/C++ source code in multiple formats, including ANSI C, EC++, and C++. Table 1 lists the various C/C++ compilers in AR
[Microcontroller]
ARM C/C++ Compiler
Design and implementation of automatic storage cabinet based on AT89C52 single chip microcomputer
1. Requirement information: In large supermarkets, libraries, trains and bus stations, people often need to store packages. Manual methods of storing and retrieving packages are labor-intensive and time-consuming, which is incompatible with the information society. Therefore, the author designed a microcomputer
[Microcontroller]
Design and implementation of automatic storage cabinet based on AT89C52 single chip microcomputer
Design and implementation of base station monitoring terminal based on μC/OS-II
In recent years, with the rapid development of mobile communication services, especially the construction of 3G communication networks, the number of communication base stations has increased day by day. Communication operators have more urgent requirements for rapid base station construction and reduction of comprehe
[Microcontroller]
Design and implementation of base station monitoring terminal based on μC/OS-II
Pay attention to the data operation exceeding the range in C language
Note: If the calculation formula can be written in one long line, write it separately, as long as the accuracy is guaranteed! ! Writing a long line may affect the accuracy! For example: unsigned long int X; double AD; AD=AD/50.0; X=AD*5000.0000/1023.00; It is best to calculate locally first,
[Microcontroller]
PIC16F877 controls the digital display of the number of times a button is pressed C language program
//Dynamic scanning of digital tube, press k1, the number +1, press K2, the number -1, and hear two DD sounds each time it is pressed. #include pic.h #define uchar unsigned char #define uint unsigned int __CONFIG(0x3B31); uint a; const uchar aa = {0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90}; v
[Microcontroller]
AT24C02 subroutine based on AVR microcontroller
/********************************************************************          Purpose: Create AT24C02 operation library Target system: Based on AVR microcontroller                                                  Application software: ICCAVR                                                       **********************
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号