.


:




:

































 

 

 

 


-. . .




- , -, . - , -. - .

 

- , . - . , -, , . - , (public, private,..).

 

- . - , . main() .

 

, - . . , - .

 

- static. , - ms_ObjCounter . , - m_Data , :

 

class Test

{

// - ( )

static int ms_ObjCounter;

 

// () - ( )

int m_Data;

 

public:

 

//

Test (int _data)

: m_Data(_data)

{

// , -

ms_ObjCounter++;

}

 

//

Test (const Test & _test)

: m_Data(_test.m_Data)

{

//

ms_ObjCounter++;

}

};

 

- - -.

 

, - public, , . :

 

● , + , + :

 

Test t;

std::cout << t.ms_ObjCounter;

 

Test * pTest = & t;

std::cout << pTest->ms_objCounter;

 

● ( !):

 

std::cout << Test::ms_objCounter;

 

, - , , . , , .

 

- , - . - . ++ :

 

int Test::ms_ObjCounter;

 

static .

 

, . , . . , , :

 

int Test::ms_ObjCounter = 5;

 

-, - , :

 

error LNK2001: unresolved external symbol "private: static int Test::ms_ObjCounter" (?ms_ObjCounter@Test@@0HA)

 

-. . , , , , , . , , . , . .

 

. #include, .

 

- (char, short, int, long, ). , (internal linkage). , , . , , . , :

 

class Queue

{

static const int QUEUE_LENGTH = 100;

int m_QueueData[ QUEUE_LENGTH ];

};

 

++, ++'11, - , . , , ( , ).

 

 





:


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


:

:

: , , , , .
==> ...

1334 - | 1231 -


© 2015-2024 lektsii.org - -

: 0.015 .