c/c++_static±äÁ¿µÄÓ¦ÓÃ
ÔÚCÓïÑÔ±à³ÌÖУ¬staticµÄÒ»¸ö×÷ÓÃÊÇÐÅÏ¢ÆÁ±Î£¡
±È·½Ëµ£¬Äã×Ô¼º¶¨ÒåÁËÒ»¸öÎļþ -- ¸ÃÎļþÖÐÓÐһϵÁеĺ¯ÊýÒÔ¼°±äÁ¿µÄÉùÃ÷ºÍ¶¨Ò壡
ÄãÏ£Íû¸ÃÎļþÖеÄһЩº¯ÊýºÍ±äÁ¿Ö»Äܱ»¸ÃÎļþÖеĺ¯ÊýʹÓã¬ÄÇô£¬Äã¿ÉÒÔÔڸú¯Êý¡¢±äÁ¿µÄÇ°Ãæ¼ÓÉÏstatic£¬´ú±íËûÃÇÖ»Äܱ»µ±Ç°ÎļþÖеĺ¯ÊýʹÓã¡
¶øÔÚC++ÖУ¬ÓÃstaticÀ´×÷ΪÐÅÏ¢ÆÁ±Î¾ÍÏÔµÃûÓбØÒªÁË£¡ÒòΪ£¬C++ÓÐÁËÐÅÏ¢ÆÁ±ÎµÄÀûÆ÷ -- class»úÖÆ£¡
ÀàÖеÄprivateÊôÐԵıäÁ¿ºÍº¯Êý¾Í¶ÔÍâ½ûÖ¹·ÃÎÊ£¡
È»ºóÊÇC/C++ͨÓõĺ¯Êý×÷ÓÃÓòµÄstaticÐ͵ıäÁ¿£¡ÆäÄ¿µÄ£¬Ò²ÊÇΪÁËÐÅÏ¢µÄÆÁ±Î£¡
int fun() {
static int a = 1;
a++;
}
ÔÚµÚÒ»´Î½øÈëÕâ¸öº¯ÊýµÄʱºò£¬±äÁ¿a±»³õʼ»¯Îª1£¡²¢½Ó×Å×ÔÔö1£¡
ÒÔºóÿ´Î½øÈë¸Ãº¯Êý£¬a¾Í²»»á±»Ôٴγõʼ»¯ÁË£¬½ö½øÐÐ×ÔÔö1µÄ²Ù×÷£¡
ÔÚstatic·¢Ã÷ǰ£¬Òª´ïµ½Í¬ÑùµÄ¹¦ÄÜ£¬ÔòÖ»ÄÜʹÓÃÈ«¾Ö±äÁ¿£º
int a = 1;
int fun() {
a++;
}
ÄÇô£¬aµÄÖµ¾ÍÓпÉÄܱ»ÆäËûº¯ÊýËù¸Ä±ä£¡
×îºó£¬ËµËµÀàÖеÄstatic±äÁ¿ºÍº¯Êý¡£
ÕâÖÖ´æ´¢ÊôÐԵıäÁ¿ºÍº¯ÊýÊÇͬһÖÖÀàµÄ²»Í¬ÊµÀýÖ®¼äͨÐŵÄÇÅÁº£¡
#include <iostream>
using namespace std;
class A {
public:
static int num; // ͳ¼Æ´´½¨Á˶àÉÙ¸öʵÀý
A () {num++}; // ÿ´´½¨Ò»¸öʵÀý£¬¾ÍÈÃnum×ÔÔö1
// ·µ»ØÍ¨¹ý¹¹Ô캯ÊýËù´´½¨¹ýµÄAÀàʵÀýµÄÊýÄ¿
static int how_many_instance() {
return num;
}
}
static A::num = 0; // ÐèÒªÔÚÀàÉêÃ÷µÄÍⲿµ¥¶À³õʼ»¯£¡
int main() {
cout << A::how_many_instance() << endl;
A a, b, c, d;
cout << A::how_many_instance() << endl;
Ïà¹ØÎĵµ£º
×ªÔØ×Ô£ºhttp://www.cnblogs.com/chio/archive/2007/11/26/972152.html
CRTÔÏÈÊÇÖ¸Microsoft¿ª·¢µÄC Runtime Library£¬ÓÃÓÚ²Ù×÷ϵͳµÄ¿ª·¢¼°ÔËÐС£ºóÀ´ÔÚ´Ë»ù´¡ÉÏ¿ª·¢ÁËC++ Runtime Library£¬ËùÒÔÏÖÔÚCRTÊÇÖ¸Microsoft¿ª·¢µÄC/C++ Runtime Library¡£ÔÚVCµÄCRT/SRCĿ¼Ï£¬¿ÉÒÔ¿´µ½CRTµÄÔ´Â룬²»½öÓÐCµÄ£¬Ò²ÓÐC++µ ......
C1XÊÇCÓïÑÔ¼´C99±ê×¼Ö®ºó½«ÒªÍƳöµÄ×îбê×¼£¬Á˽⵽µÃÔÎÄÈçÏ£º
C1X is the unofficial name of the planned new standard for the C programming language. It is intended to replace the existing C standard. This predecessor is informally known as C99. The standard is not yet fin ......
1 ÏÂÔØ°²×°jre£¬Eclipse±¾ÉíÊÇJava³ÌÐò£¬ÔËÐеÄʱºòÐèÒªjre¡£
2 ÏÂÔØEclispe for C/C++£¬½âѹµ½ÈÎÒâλÖá£
3 ÏÂÔØMingw°²×°³ÌÐò£¬ÔËÐУ¬Ñ¡ÔñÐèÒªµÄ×é¼þ£¬ÎÒÑ¡ÔñÁËg++±àÒëÆ÷ºÍMakefile¹¤¾ß£¬Ëü»á×Ô¶¯ÏÂÔØ°²×°¡£
4 ÏÂÔØ°²×°gdbµ½MingwµÄ°²×°Ä¿Â¼£¬gdbµÄbinºÍincludeĿ¼»áºÍMingwµÄͬÃûĿ¼ºÏ²¢µÄ¡£
ÏÂÃæ¿ªÊ¼ÅäÖÃEclipse¡ ......
Regarding C Run-Time Error R6034 for VS2005/VS2008
Regarding "C Run-Time Error R6034"
Microsoft's recommendation is very confusing. That is, it recommends to include a manifest file and to re-compile the project.
I recently had a problem with 'R6034' error message even with a manifest file ......