C++ extensions to the use of C language constructs
- 2020-06-12 10:07:21
- OfStack
Recently, when I studied C++, I learned that C has been extended in C++. When using the structure, I can specify private and public data types just like class 1, and also implement method Settings in struct.
To maintain the object-facing nature, however, it is recommended to use class to describe a class.
The case is as follows:
#include <iostream>
#include <ctime>
using namespace std ;
typedef struct student
{
private :
int a , b , c ;
public :
void set(int a , int b , int c)
{
this->a = a ;
this->b = b ;
this->c = c ;
}
void prit()
{
cout << a << endl << b << endl << c << endl ;
}
}stu;
stu st1 ;
int main(void)
{
st1.set(1,2,3);
st1.prit();
return 0 ;
}
Operation results:
[
1
2
3
conclusion