.
class test{ private: int i; public: test(int _w=0){i=_w;cout<<"sozd ob i="<<i<<endl;} ~test(){cout<<"razrush ob i="<<i<<endl; } void print(){ cout<<" i="<<i<<endl;} }; main(){ test a(1); a.print(); test b; b.print(); ... } |
:
test() {i=0;}// test(int _i) { i=_i;}// test(int _i=10){i=_i;}// |
- . test print test i.
: ,
test a(1), b; |
:
test a=1;// test a=test(1); test a(1); |
: test a(1), b; a b i.
, : ,
a.print(); b.print(); |
, , -.
, test :.
class test{ private: int i; public: test(int _w=0); //- ~test(); // void print(); // }; |
, , , , :
test:: test(int _w=0) { i=_w; cout<<"sozd ob i="<<i<<endl; }; test:: ~test() {cout<<"razrush ob i="<<i<<endl; } void test:: print() { cout<<" i="<<i<<endl;} |
:: |
( ) , . |
, , ( , , ).
- ++ . |
this
- , this . this . this, , .
|
|
this . this - , . , . , , this:
return(*this);
.
primer ( show1 show2). - : this this.
#include <iostream>
using namespace std;
class primer{ char title[256];// - char autor[256]; public: primer(char*_title, char*_autor);// void show1();// this void show2();// this }; |
int main() { primer book("My life","Daria sergeeva"); book.show1(); book.show2(); return 0; } |
primer::primer(char*_title, char*_autor) {strcpy(title,_title); strcpy(autor,_autor); } void primer::show1() {cout<<this->title<<" "; cout<<this->autor<<endl; // , (.) // cout<<(*this).title<<" "; cout<<(*this).autor<<endl; } void primer::show2() { cout<<title<<" "; cout<< autor<<endl; } |
My life Daria sergeeva My life Daria sergeeva My life Daria sergeeva |
++ -:
, ,
, ( ),
, ,
, ,