.


:




:

































 

 

 

 





, , , . , , .

- , , . . , .

, . -. - . . .

. = . .

. . .

. . . .


 

4. : , , , , .

.

: , , , .

. , .

.

- . : ,

, . , .

, , . : ->


 

5. : , , .

- , . .

. - ,

- , .. . , . . ()

, , () , . - . (JSON,XML)


 

6. : -.

, , .

:

, , ;

, , ;

, , . .

, , .

.

1. ;

2. ( ) ;

3. .

4. - .


 

7. : .

, . . .

, , . . . diamondproblem

. , .

.

. , , , .

.

/ : (, , . .) ,


 

8. : , , . .

, , , .

class A

{

public:

int a, b; //

intReturnSomething(); //

private:

intAa, Ab; //

voidDoSomething(); //

};

, . , , , . , .

class A{ //

};

class B: A{ //

};

.

abstract class Animal {

String talk();

}

class Cat extends Animal {

String talk() { return "Meow!"; }

}

class Dog extends Animal {

Stringtalk() { return "Woof!"; }

}


 

9. , . .

( ) (). , . , .

,

.

. . .

.

, //, , , . , ( ) .

, ( ), , , ( ).

. .

. .


 

10. .

: , ,

-

-

-

-

- - ,

- /

-

-

- . , .

- ,


 

11. .

- , . , , . .

() . , . , . . , C++ , operator==. . , . , , . , . C++ , new delete.


 

12. . , .

- Private. , private . private , .

- Public. , , public , .. . , public, .

- Protected. , , protected, ; . private, protected , , , , . .


 

13. , .

.

. , , . , , , .

:

class Animal { }

class Cat extends Animal { }

classDogextendsAnimal { }

. , - - , ..

class A {

public:

voiddoSmth() { }

};

class B {

public:

voiddoSmth() { }

};

class C: public A, public B { };

C::doSmth() , .. , : A B. : Csome; some.B::doSmth();

C++ , , . , . .

classILoad {

public:

virtualvoidStartLoading()=0;

virtualboolIsFinish()=0;

};

classCImg: public ILoad {

public:

virtual void StartLoading()

{printf("Img ->StartLoading");}

virtualboolIsFinish()

{ return true;}

};


 

14. .

C++ : public, protected, private. :

public, public public , protected protected .

protected, public protected protected .

private, public protected private .


 

15. .

C++ .

const_cast<> - const volatile. volatile const_cast .

dynamic_cast<> - , , NULL . RTTI (run-time type identification).

class Base {

public: virtual ~Base();

} * pBase;

class Derived: Base{};

Derived *pDerived = dynamic_cast(pBase);

:

if (typeid(Derived) == typeid(*pBase)) {

pDerived = (Derived*)pBase;

}

, , , ((Derived*)pBase) , dynamic_cast , Derived . VS . typeid , . typeid :

class A {...};

class B: public A {...};

class C: public B {...};

A *c = new C;

if (typeid(B) == typeid(*c)) {...}

dynamic_cast . , , , .

, ?

: , :

1.Derived *pDerived = new Derived();

2.Base *pBase = pDerived;

, .

static_cast<> - , (.. ) . . , . dynamic_cast B* A*, B A, . B A , .

static_cast<> const volatile, .

reinterpret_cast<> - , , . . char* int, A* B*, - . reinterpret_cast , , static_cast.

reinterpret_cast , , .


 

16. .

. , . : - .. , . .. . ++ , , .

( ) - () , - , . , : , , .

. , , -. . , Java, , , , . (, , Python), .

, . ( . purevirtual) . , , . ( , ). , , , .

, , . . : , , , , . , .


 

17. . .

, . :

void;

;

;

;

, ;

.

, . , . . , . , .

, , ~. , .


 

18. , .

- , , . () , , , , , . , , , . , , , . . . , , public, private. abstract. : , , . . , abstract, . , , . , private, , . , . final . , , private- . , native, .


 

19. .

- - , . - . ( ) . , , - . - , .

- , (, Delphi), . , (, Java), . , , , , , .

, - .

 


 

20. .

. , , , , . . , . , , , . . (, ), . , , .


 

21. .

, , . static. . , , , , . , . , Person message, .

, , static. , . , . . , .

- , . , Person , message. , .

. .

:

public class C {

public C() { }

staticint b=3;

staticint c;

static{ b++; c = 10; }//

}

, , , . , ++ ::


22. . .

́́́ (. exceptionhandling) , (), () . : .

, , - . .

. , , .

. , .

. - , .

. , , , ( - ) .

, . , , .

, , : , .

, . , , , .

, . : .


 

23. . . , .

.

.

.

.

.

.

.

.

.

.





:


: 2016-07-29; !; : 1085 |


:

:

, , .
==> ...

1847 - | 1719 -


© 2015-2024 lektsii.org - -

: 0.097 .