.
- ++, ++. || '. '- : , , .
, ++ - , .
|,| |',| . :
_ _{ __};
_ class, struct, union;
_ ;
__ , , , .
, '.
', . '.
||.
struct date //
{int month,day,year; // : , ,
void set(int,int,int); //
void get(int*,int*,int*); // ||
void next(); // ||
void print(); //
};
struct class complex //
{double re,im;
double real(){return(re);}
double imag(){return(im);}
void set(double x,double |,|){re = x; im = |,|;}
void print(){cout<<re = <<re; cout<<im = <<im;}
};
' (|| )
_ _ᒺ;
date today,my_birthday;
date *point = &today; // ' date
date clim[30]; // '
date &name = my_birthday; // || '
', , , - . - ' . || ' || ' . :
_ᒺ _
_ _
:
complex x1,x2;
x1.re = 1.24;
x1.im = 2.3;
x2.set(5.1,1.7);
x1.print();
'
_ ' >_
complex *point = &x1; // point = new complex;
point >re = 1.24;
point >im = 2.3;
point >print();
.
|| || |',| . - , || , ' . (||) '. : public, private, protected.
(public) - || . - , || . ' ':
|
|
_ᒺ. __
_ _ ᒺ. __
_ _ ᒺ. __
(private) . , .
(protected) - .
|| || class. |',|
||.
class complex
{
double re, im; // private
public:
double real(){return re;}
double imag(){return im;}
void set(double x,double |,|){re = x; im = |,|;}
};
.
|| || |',| '. ' || set ( complex) '. || ' , . ||:
' _(__){ __}
' || ++ || || ' . || ' new ' .
||.
omplex(double re1 = 0.0,double im1 = 0.0){re = re1; im = im1;}
' ' - .
|,| :
* , . void .
* , || .
* ||.
* || || virtual, static, const, mutuable, valatile.
- , , , . . , . (public).
, || || (T&). || (||) '. || . :
' _ ' _ᒺ (_);
' _ (_);
|| || . ' :
|
|
complex ss (5.9,0.15);
|,| || ' :
complex ss = complex (5.9,0.15);
' . || , . || . | . | ||:
_ (||)
||.
class CLASS_A
{
int i; float e; char ||;
public:
CLASS_A(int ii,float ,char cc): i(8),e(i * + ii),(|){
...
};
.
#include <string.h>
#include <iostream.h >
class string
{
char *ch; //
int len; //
public:
//
// ' ||
string(int N = 80): len(0){ch = new char[N+1]; ch[0]= 0;}
// '
string(const char *arch){len = strlen(arch);
ch = new char[len+1];
strcpy(ch,arch);}
// -
// ||
int& len_str(void){return len;}
//
char *str(void){return ch;}
...};
|,| string || .
||
T::T(const T&),
' . || || , ', . ||:
) ' ;
) || ' ;
) ' '.
|| , |,| '. |',| . . , string:
string(const string& st)
{len=strlen(st.len);
ch=new char[len+1];
strcpy(ch,st.ch); }
', || ( ).
' , .
class demo{
int x;
public:
demo(){x=0;}
demo(int i){x=i;}
};
void main(){
class demo [20]; // ( )
class demo b[2]={demo(10),demo(100)}; //
.
' ' || ' '. , ' , , || , ' , ' . , || ' || . || . :
~_(){ __}
' || || ' , || ~ ().
.
(), ' .
, delete ':
string *p=new string ();
|
|
delete p;
, , || ', |,| '. , || ' ', , || ch ' string, : ~string(){delete []ch;}
, , .