Starting with the basic data type:
In general, the basic data types in C + + have int, char,,,,
However, these data types are limited and are self-contained in C + + and lack flexibility
C + + provides a way to define a custom type----use structs (struct)
But the structure also has his limitations:
1 How data is organized in a struct
2 The data in the struct has no access restrictions, which makes it easy to modify the data arbitrarily
3 structure data is not inherited
In order to solve these problems. C + + provides a class
As a result, we'll know:
So we can understand the class in C + +
Collection of data + operation of data =class
Some misconceptions about C + + and Java:
#include <cstdlib>
#include <iostream>
using namespace Std;
Class Student
{
/**
Personal advice put the public on the back there's a problem yellow
**/
Public:
char* getName ()//Array life
{
return name;
}
void SetName (char* c)
{
name = &c;
}
/** constructor function
**/
Student ()
{
age=1;
gender=0;
}
~student ()
{
cout << "123";
}
void Dispaly ()
{
cout << "name=:" << name << Endl
<< "age=:" << age << Endl;
}
Private:
Char name[20];
int age;
BOOL gender;
} ;
int main (void)
{
Student s;
S. dispaly ();
System ("PAUSE");
return exit_success;
}
Suggestions:
The fewer statements in the main () function, the better, it's best to put all the definitions in the *.h file
This can separate the representation from the definition;
A simple class for C + +