ChinaUnix.net
相关文章推荐:

怎么理解虚继承

有一段代码如下: #include "stdio.h" void main(void){ class A {}; class B : virtual public A {}; class C: public A {}; class D: public B, public C {}; class E: virtual public B, virtual public C {}; printf("sizeof(A) = %d\n",sizeof(A)); printf("sizeof(B) = %d\n",sizeof(B)); printf("sizeof(C) = %d\n",sizeof(C)); printf("sizeof(D) = %d\n",sizeof(D)); printf("sizeof(E) = %d\n",sizeof(E)); } ...

by notcat - C/C++ - 2009-09-01 19:11:24 阅读(2178) 回复(3)

相关讨论

研究了一下继承时,对象的内存分布模型,写了下面这个小程序 #include struct A {int x;int y; }; struct B : virtual public A { int a; B(){x=1;y=2;a=55;} }; struct C : virtual public A { int b; C(){x=3;y=4;b=66;} }; struct D : public B, public C { };//菱形继承 int main(void) { A a; B b; C c; D d; D *pd = &d; C *pd_c =(C*)(&d); B *pd_b =(B*)(&d); A *pd_a =(A*)(&d); printf("%d,%d,%d,%d\n",s...

by jeanlove - C/C++ - 2009-03-02 14:41:50 阅读(1333) 回复(3)

#include ; class Base { public: virtual void g(void){ cout << "Base::g(void)" << endl;} }; class Derived : public Base { public: virtual void g(void){ cout << "Derived::g(void)" << endl;} }; void main(void) { Derived d; Base p(d); Base *pb = & p.g(); pb->;g(); } 请问一下,主函数里面执行后的结果是什么?说明一下理由最好了,...

by SCUguoguo - C/C++ - 2004-06-21 22:52:27 阅读(1401) 回复(7)

存的理解有点模糊,影响其大小的因素有哪些呢?

by ydar - AIX - 2003-04-16 08:11:02 阅读(831) 回复(3)

存的理解有点模糊,影响其大小的因素有哪些呢?

by ydar - 内核/嵌入技术 - 2003-04-17 14:01:52 阅读(890) 回复(2)

// world.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using std::cout; using std::cin; using std::endl; class X{ int y; }; class A{ public: virtual void go(){}; int x; }; class B :virtual public A{ int x; }; class C : public virtual A{ int x; }; class D :virtual public B,virtual public C{ int x; }; ...

by daydayhappyacm - C/C++ - 2009-04-24 20:54:45 阅读(2457) 回复(3)

printf "%d\n", (unsigned long)(&((struct inode *)0)->i_list怎么理解(&((struct inode *)0)->i_list

by udb6688 - C/C++ - 2009-01-08 22:36:44 阅读(1508) 回复(5)

runq-sz – The average number of kernel threads in memory waiting for a CPU to run. Typically, this value should be less than 2. Consistently higher values mean that the system may be CPU bound.

by Kamus_cu - HP-UX - 2007-08-11 12:57:46 阅读(2792) 回复(1)
by Alex.Xia - Perl - 2006-06-30 13:32:52 阅读(1240) 回复(3)

请教高手有关c++中的派生、多态和函数的问题。 以下是我做的测试程序, 基类 class A { public : A ( const char* v_name ); protected : virtual void updateSelf( const char * obj){cout << "run in A class " << endl;}; private : void update( const char * v_obj){ updateSelf ( const char * v_obj)}; } 派生类 class B { public : B ( const char* v_name ); protected : virtual void updateSelf(...

by h2002lg37 - C/C++ - 2005-12-16 14:50:53 阅读(5115) 回复(15)

/* * Created on 2004-8-31 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author diyer6 * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ /* 类的继承 1、在java中通过关键字 extends 继承一个已有的类,被继承的类成为父类(基类),新的类...

by softiger - Java文档中心 - 2006-08-28 10:57:44 阅读(824) 回复(0)