C++¼Ì³ÐááµÄ½¨¹¹º¯Ê½ºÍ½â¹¹º¯Ê½_C/C++ÓïÑÔ_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

C++¼Ì³ÐááµÄ½¨¹¹º¯Ê½ºÍ½â¹¹º¯Ê½

×÷ÕߣººÚ¿Í·ÀÏßÍø°²C/C++½Ì³Ì»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²C/C++½Ì³Ì»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£ººÍ½â½¨¹¹¼Ì³ÐÀà±ð
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£º  ¡¡ÈôÄú¼Ì³ÐÁËij¸öÀà±ðÖ®áᣬµ±ÄúÔÚÉú³ÉÑÜÉúÀà±ðµÄÎï¼þʱÈô²»Ö¸¶¨²ÎÊý£¬ÎÞ²ÎÊýµÄÔ¤É轨¹¹×ӻᱻִÐУ¬¶ø»ù´¡Àà±ðµÄÎÞ²ÎÊýÔ¤É轨¹¹×ÓÒ²»á±»Ö´ÐУ¬ËùÒÔ»ùì¶ÕâÖÖÌØÐÔ£¬Í¨³£Ô¤É轨¹¹×ÓÖлá׫д...
  ¡¡ÈôÄú¼Ì³ÐÁËij¸öÀà±ðÖ®áᣬµ±ÄúÔÚÉú³ÉÑÜÉúÀà±ðµÄÎï¼þʱÈô²»Ö¸¶¨²ÎÊý£¬ÎÞ²ÎÊýµÄÔ¤É轨¹¹×ӻᱻִÐУ¬¶ø»ù´¡Àà±ðµÄÎÞ²ÎÊýÔ¤É轨¹¹×ÓÒ²»á±»Ö´ÐУ¬ËùÒÔ»ùì¶ÕâÖÖÌØÐÔ£¬Í¨³£Ô¤É轨¹¹×ÓÖлá׫дһЩͨÓõijÉԱ״̬³õʼ£¬ÀýÈçÉ趨һЩԤÉèÖµ¡£
¡¡¡¡Èç¹û¼Ì³ÐÖ®áᣬÄúҪʹÓÃÑÜÉúÀà±ðÉú³ÉÎï¼þ£¬ÔÚÉú³ÉÎï¼þʱָ¶¨²ÎÊý£¬²¢Í¬Ê±Ö´Ðлùµ×Àà±ðÖеÄij¸ö²ÎÊý½¨¹¹×Ó£¬Äú¿ÉÒÔʹÓà : ÔËËã×Ó
ÀýÈ磺
// Point2DÀà±ð
class Point2D {
public:
Point2D() {
_x = 0;
_y = 0;
}
Point2D(int x, int y) : _x(x), _y(y) {
}
private:
int _x;
int _y;
};
// Point3DÀà±ð
class Point3D : public Point2D { // ¼Ì³ÐPoint2DÀà±ð
public:
Point3D() {
_z = 0;
}
// ½¨¹¹º¯Ê½£¬Í¬Ê±Ö¸¶¨ºô½Ð¸¸Àà±ð½¨¹¹º¯Ê½
Point3D(int x, int y, int z) : Point2D(x, y), _z(z) {
}
private:
int _z; // ÐÂÔö˽ÓÃ×ÊÁÏ
};
¡¡¡¡Èç¹ûÄúʹÓÃÑÜÉúÀà±ðÉú³ÉÎï¼þ£¬Ôò½¨¹¹º¯Ê½µÄÖ´ÐÐ˳Ðò»á´Ó»ùµ×Àà±ðµÄ½¨¹¹º¯Ê½¿ªÊ¼Ö´ÐÐÆð£¬ÕâÊÇ¿ÉÒÔÀí½âµÄ£¬ÒòΪ»ùµ×Àà±ðÊÇÑÜÉúÀà±ðµÄ»ù´¡£¬Ò»Ð©»ù´¡µÄ²ÎÊý»ò³õʼ״̬±ØÐëÏÈÍê³É£¬ÔÙÀ´ÔÙÍê³ÉÑÜÉúÀà±ðÖеĽ¨¹¹º¯Ê½¡£
¡¡¡¡¶øÔÚÎï¼þ±»ÏûÃðʱ£¬½â¹¹º¯Ê½µÄÖ´ÐÐ˳ÐòÔòÕýºÃÏà·´£¬ÊÇ´ÓÑÜÉúÀà±ðµÄ½â¹¹º¯Ê½¿ªÊ¼Ö´ÐУ¬ÔÙÀ´²ÅÊÇ»ù´¡Àà±ðµÄ½¨¹¹º¯Ê½£¬ÒòΪÈô»ùµ×Àà±ðµÄ½â¹¹º¯Ê½Èç¹ûÏÈÖ´ÐУ¬ÔòÑÜÉúÀà±ðÏàÒÀ춻ùµ×Àà±ðµÄһЩ״̬Ҳ»á±»½â¹¹£¨ÀýÈçÖ¸±ê£©£¬Ôò´ËʱÔÙÐÐÑÜÉúÀà±ðµÄ½â¹¹º¯Ê½£¬½«´æÔÚ×ÅÏàÒÀÎÊÌâ¶øÔì³É´íÎó¡£
¡¡¡¡ÏÂÃæÕâ¸ö¼òµ¥µÄ³Ìʽ¿ÉÒÔ¸æËßÄú½¨¹¹º¯Ê½Óë½â¹¹º¯Ê½£¬Ôڼ̳ÐÖ®ááµÄÖ´ÐÐ˳Ðò£º
#include <iostream> using namespace std; class Foo1 { public:
Foo1() {
cout << "Foo1½¨¹¹º¯Ê½" << endl;
}
~Foo1()
{
cout << "Foo1½â¹¹º¯Ê½" << endl;
}
};
class Foo2 : public Foo1 { public:
Foo2() {
cout << "Foo2½¨¹¹º¯Ê½" << endl;
}
~Foo2() {
cout << "Foo2½â¹¹º¯Ê½" << endl;
}
};
int main()
{
Foo2 f;
cout << endl;
return 0;
}
Ö´Ðнá¹û£º
Foo1½¨¹¹º¯Ê½
Foo2½¨¹¹º¯Ê½
Foo2½â¹¹º¯Ê½
Foo1½â¹¹º¯Ê½
    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-15385-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-04-04 22:54:12  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer