4.
, . . , , . , , "", , . " " " - ". . - , .
- ( ) :
class Complex {public: int real; // int imaginary; // // void Add(Complex x) { real = real + x.real; imaginary =imaginary + x.imaginary; }};
, .
int i=1; //
Struct tColor
{
int r;int g;int b;
};
tColor color={255,0,0}; //
Complex number={10,6}; // !!!
, , , . , . -. -.
, , . .
- , . , . .
. :
Complex number;
, . , .
.
:
Complex(int p1,int p2); : Complex::Complex(int p1,int p2){ real=p1; imaginary=p2;}Complex.
Complex number(10,5);
, ? .
|
|
:
Complex(); : Complex::Complex(){}, , . , , . , .
, Complex
class Complex {public: int real; // int imaginary; // Complex(); // 1 Complex(int p1,int p2);// 2 // void Add(Complex x); };
, , .
, , , -, . "".
, new , delete .
, : , (~). Complex .
:
~Complex(); Complex , , . , : Complex::~Complex(){}, , , :
Complex::~Complex(){cout "Bye!\n";
}, . , , , .
, .. (), . , , . ++ , , , .. , "", , . , , . - , - . .
ü ,
ü ,
ü .
public, . . , , , . , - , Public , .
|
|
.
, . , , . , :
class String{ public: // void Concat(const String str); // void ToLower(void); // int GetLength(void) const;...};
, - .
private. - , Private, (.. - ) (friend) , , .
protected. (private), (protected) , , , . , , - , protected.
public, private, protected .
.
class String{ public: // void Concat(const String str); // void ToLower(void); // int GetLength(void) const; private: char* str; int length;};
, , . , , String , length.
str length private, , , .
:
int String::GetLength(void) const{ return length;}, .
Concat :
void String::Concat(const String x){ length += x.length; char* tmp = new char[length + 1]; strcpy(tmp, str); strcat(tmp, x.str); delete [] str; str = tmp;}, , :
main(){ String s; if (s.length > 0) // ... }() , . , , . , . . .