CÖÐexternÐÞÊηûµÄÓ÷¨
ÔÚCÓïÑÔÖУ¬ÐÞÊηûexternÓÃÔÚ±äÁ¿»òÕߺ¯ÊýµÄÉùÃ÷Ç°£¬ÓÃÀ´ËµÃ÷“´Ë±äÁ¿/º¯ÊýÊÇÔڱ𴦶¨ÒåµÄ£¬ÒªÔÚ´Ë´¦ÒýÓÔ¡£
Ò».externÐÞÊαäÁ¿µÄÉùÃ÷
¾ÙÀýÀ´Ëµ£¬Èç¹ûÎļþa.cÐèÒªÒýÓÃb.cÖбäÁ¿int v£¬¾Í¿ÉÒÔÔÚa.cÖÐÉùÃ÷extern int v£¬È»ºó¾Í¿ÉÒÔÒýÓñäÁ¿v¡£ÕâÀïÐèҪעÒâµÄÊÇ£¬±»ÒýÓõıäÁ¿vµÄÁ´½ÓÊôÐÔ±ØÐëÊÇÍâÁ´½Ó£¨external£©µÄ£¬Ò²¾ÍÊÇ˵a.cÒªÒýÓõ½v£¬²»Ö»ÊÇÈ¡¾öÓÚÔÚa.cÖÐÉùÃ÷extern int v£¬»¹È¡¾öÓÚ±äÁ¿v±¾ÉíÊÇÄܹ»±»ÒýÓõ½µÄ¡£ÕâÉæ¼°µ½cÓïÑÔµÄÁíÍâÒ»¸ö»°Ì⣣±äÁ¿µÄ×÷ÓÃÓò¡£Äܹ»±»ÆäËûÄ£¿éÒÔexternÐÞÊηûÒýÓõ½µÄ±äÁ¿Í¨³£ÊÇÈ«¾Ö±äÁ¿¡£»¹ÓкÜÖØÒªµÄÒ»µãÊÇ£¬extern int v¿ÉÒÔ·ÅÔÚa.cÖеÄÈκεط½£¬±ÈÈçÄã¿ÉÒÔÔÚa.cÖеĺ¯Êýfun¶¨ÒåµÄ¿ªÍ·´¦ÉùÃ÷extern int v£¬È»ºó¾Í¿ÉÒÔÒýÓõ½±äÁ¿vÁË£¬Ö»²»¹ýÕâÑùÖ»ÄÜÔÚº¯Êýfun×÷ÓÃÓòÖÐÒýÓÃv°ÕÁË£¬Õ⻹ÊDZäÁ¿×÷ÓÃÓòµÄÎÊÌâ¡£¶ÔÓÚÕâÒ»µãÀ´Ëµ£¬ºÜ¶àÈËʹÓõÄʱºò¶¼ÐÄ´æ¹ËÂÇ¡£ºÃÏñexternÉùÃ÷Ö»ÄÜÓÃÓÚÎļþ×÷ÓÃÓòËƵġ£
Èç¹ûÔÚÉùÃ÷Ç°¼ÓÁËextern¹Ø¼ü×Ö£¬ÄǾͱíʾÕâ¸ö±äÁ¿ÊÇÔÚÆäËûµØ·½¶¨ÒåµÄ£¬ Èç¹ûÔÚ.cppÎļþÖÐÉùÃ÷Ò»¸öÈ«¾Ö±äÁ¿£¬ÄÇôÕâ¸ö±äÁ¿µÄ×÷ÓÃÓò¾ÍÊÇÕâ¸öÎļþ¡£Èç¹ûÒªÔÚÆäËûÎļþÖÐʹÓã¬ÄÇô¾ÍÐèÒªÔÚÆäËûÎļþµÄÉùÃ÷Ç°Ãæ¼ÓÉÏextern
/// Declare.cpp
// È«¾Ö±äÁ¿ÉùÃ÷
int iGlobal;
/// other.cpp
// ʹÓÃDeclare.cppÖеÄiGlobal
extern int iGlobal;
µ«ÊÇ£¬Èç¹ûÊÇ°ÑÈ«¾Ö±äÁ¿·Åµ½.hÎļþÖÐÉùÃ÷£¬ÄÇô£¬Ö»ÐèÒª°üº¬Õâ¸ö.hÎļþ¼´¿ÉʹÓã¬ÎÞÐèÓÃextern¹Ø¼ü×Ö¡£
¶þ. externÐÞÊκ¯ÊýÉùÃ÷¡£
´Ó±¾ÖÊÉÏÀ´½²£¬±äÁ¿ºÍº¯ÊýûÓÐÇø±ð¡£º¯ÊýÃûÊÇÖ¸Ïòº¯Êý¶þ½øÖƿ鿪ͷ´¦µÄÖ¸Õë¡£Èç¹ûÎļþa.cÐèÒªÒýÓÃb.cÖеĺ¯Êý£¬±ÈÈçÔÚb.cÖÐÔÐÍÊÇint fun(int mu)£¬ÄÇô¾Í¿ÉÒÔÔÚa.cÖÐÉùÃ÷extern int fun£¨int mu£©£¬È»ºó¾ÍÄÜʹÓÃfunÀ´×öÈκÎÊÂÇé¡£¾ÍÏñ±äÁ¿µÄÉùÃ÷Ò»Ñù£¬extern int fun£¨int mu£©¿ÉÒÔ·ÅÔÚa.cÖÐÈκεط½£¬¶ø²»Ò»¶¨·ÇÒª·ÅÔÚa.cµÄÎļþ×÷ÓÃÓòµÄ·¶Î§ÖС£¶ÔÆäËûÄ£¿éÖк¯ÊýµÄÒýÓã¬×î³£Óõķ½·¨ÊÇ°üº¬ÕâЩº¯ÊýÉùÃ÷µÄÍ·Îļþ¡£Ê¹ÓÃexternºÍ°üº¬Í·ÎļþÀ´ÒýÓú¯ÊýÓÐʲôÇø±ðÄØ£¿externµÄÒýÓ÷½Ê½±È°üº¬Í·ÎļþÒª¼ò½àµÃ¶à£¡externµÄʹÓ÷½·¨ÊÇÖ±½ÓÁ˵±µÄ£¬ÏëÒýÓÃÄĸöº¯Êý¾ÍÓÃexternÉùÃ÷Äĸöº¯Êý¡£Õâ´ó¸ÅÊÇKISSÔÔòµÄÒ»ÖÖÌåÏÖ°É£¡ÕâÑù×öµÄÒ»¸öÃ÷ÏԵĺô¦ÊÇ£¬»á¼ÓËÙ³ÌÐòµÄ±àÒ루ȷÇеÄ˵ÊÇÔ¤´¦Àí£©µÄ¹ý³Ì£¬½Úʡʱ¼ä¡£ÔÚ´óÐÍC³ÌÐò±àÒë¹ý³ÌÖУ¬ÕâÖÖ²îÒìÊǷdz£Ã÷ÏԵġ£
Èý. ´ËÍ⣬externÐÞÊηû¿ÉÓÃÓÚָʾC»òÕßC£«£«º¯ÊýµÄµ÷Óù淶¡£
±ÈÈçÔÚC£«
Ïà¹ØÎĵµ£º
ÍøÉÏÒ»µÀ½ðɽµÄÃæÊÔÌ⣺
http://topic.csdn.net/u/20100524/14/0eff992a-2849-4db6-bdaa-d4a200e79b7c.html
Çë·Ö±ðÓÃC++µÄÃæÏò¶ÔÏóºÍ·ºÐÍ»úÖÆ£¬±àдʵÏÖTemplate MethodģʽµÄʾÀý´úÂ룬²¢±È½ÏÁ½ÖÖ·½Ê½¸÷×ÔµÄÓÅȱµã¡£
ÓÃÐ麯ÊýʵÏÖTemplate MethodµÄ·½Ê½¾Í²»¶à˵ÁË¡£Ó÷ºÐ͵ķ½Ê½ÊµÏÖ¶à̬ÔÚATLÀïÃæÓдóÁ¿µÄÓõ½£¡
·ºÐ͵ ......
/*
* File: main.cpp
* Author: Vicky
*
* Created on 2010Äê5ÔÂ8ÈÕ, ÏÂÎç2:47
*/
#include <iostream>
using namespace std;
class A{
public:
A(){
cout << "Ö´Ðй¹Ô캯Êý´´½¨Ò»¸ö¶ÔÏó" << endl;
}
A(A&){
cout << "Ö´Ðп½±´º¯Êý¿½±´Ò»¸ö¶ ......
Àý) Σ険¤Ê¥³ー¥Ç¥£¥ó¥°
1 char cStr[256];
2 ZeroMemory(cStr, sizeof(cStr));
3 &nb ......
ÔÖø£ºAndrew Koenig - AT&T Bell Laboratories Murray Hill, New Jersey 07094
·Ò룺lover_P
0 ¼ò½é
CÓïÑÔ¼°ÆäµäÐÍʵÏÖ±»Éè¼ÆΪÄܱ»×¨¼ÒÃÇÈÝÒ×µØʹÓá£ÕâÃÅÓïÑÔ¼ò½à²¢¸½Óбí´ïÁ¦¡£µ«ÓÐһЩÏÞÖÆ¿ÉÒÔ±£»¤ÄÇЩ¸¡ÔêµÄÈË¡£Ò»¸ö¸¡ÔêµÄÈË¿ÉÒÔ´ÓÕâЩÌõ¿îÖлñµÃһЩ°ïÖú¡£
&nbs ......