This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 问一个C++的问题
-oasis(oasis);
2002-1-24
{841}
(#346324@0)
-
Use constractor fuction of class Derived to do initialization.
-hairless(亮晶晶);
2002-1-24
(#346340@0)
-
我不想这么做,想一个初始化就解决问题,行吗?
-oasis(oasis);
2002-1-24
(#346367@0)
-
The following is VC win32 console application, which can output what you want.
-webcrawl(pushback);
2002-1-24
{623}
(#346412@0)
-
和我现在用的一样,不过我正在试图找一种更好的方法想一想,如果有很多data member, 岂不是很麻烦。
不过也许这是唯一的方法
-oasis(oasis);
2002-1-25
{69}
(#346422@0)
-
Another way, only need one member function to copy itself.
-webcrawl(pushback);
2002-1-25
{659}
(#346433@0)
-
太复杂了,感觉还不如直接给data member扶植
-oasis(oasis);
2002-1-25
(#346436@0)
-
Better way to initialize the member variable in constructor.
-webcrawl(pushback);
2002-1-25
{584}
(#346417@0)
-
不好用呀,小伙
-oasis(oasis);
2002-1-25
(#346435@0)
-
在VC6,怎样操作EXECL表格?那位DX能指点一下!
-icelee(ice);
2002-1-29
(#350832@0)
-
See whether this implement what you want:derived.cpp
#include "Base.h"
class Derived : public Base
{
public:
void did(){cout << "this is derived class" << endl;
cout << "tt = " << getTT() << endl;}
private:
};
base.cpp
#include <iostream.h>
class Base
{
public:
int getTT() { return tt;}
virtual void did(){};
private:
int tt;
};
int main()
{
Base *b = new Derived;
b->did();
return 0;
}
-clinux(C/Linux);
2002-1-24
{404}
(#346386@0)
-
不是我想要的我是想在base class 里面,先初始化这个base class的某个data member, 然后定义一个base class pointer, 用一个derived class的object初始化这个指针,初始化的同时,让这个drived class的data member同时也被符值(等于base class中这个data member的值)。
亮晶晶的想法是对的,可是我在derived class CONSTRUCTOR里无法得到 base class的data member 的值?(因为这个base class 和drived class之间没有继承关系)除非传进去一个this, 这样太复杂了。
-oasis(oasis);
2002-1-24
{424}
(#346414@0)
-
自寻烦恼
-blaise();
2002-1-25
(#346467@0)
-
不理解?你这样做地目的是什么?
实际上派生类初始化之前是会自动调用基类构造函数的,你在基类里的tt的值应该能够继承下来. 但是如果你的基类比较复杂,还是用copy constructor吧.
-netee(netee);
2002-1-25
{158}
(#346477@0)
-
Following is my answer, i put all the code in one file and use VC++6.0.
-smile2u(smile2u);
2002-1-25
{556}
(#346973@0)
-
这个答案比较好,如果有不止一个data member是不是有更好的方法?谢谢
-oasis(oasis);
2002-1-26
(#348533@0)
-
give you a hand"我想在base class内部,定义一个base pointer, 用derived class初始化,同时又让他是这个base class的derived class"
FYI:
1.using constructor
If you have few members.
2.using copy constructor
which can handle whatever data members you need,but it 's not always suitable.
BTW,Your code is typically bad practice in OO programming.
-steven99ca(Don);
2002-1-27
{333}
(#348664@0)
-
try search "c++ down cast" in deja.com
-netee(netee);
2002-1-27
(#348890@0)
-
如果不止一个data member, 我认为处理方法完全一样. 只是构造函数带不止一个参数而已.
-smile2u(smile2u);
2002-1-27
(#349467@0)
-
我个人认为C++ PROGRAMMERS 应该学会研究一些简单且实用的C++ 反汇编代码.你将更好理解它的精髓.
-rockman12(TianTian);
2002-1-27
(#349062@0)
-
请问你有没有反汇编的工具?如果有,给我一个. 我的地址:
smile2u2u@hotmail.com
Thanks in advance.
-smile2u(smile2u);
2002-1-27
(#349455@0)
-
Visual C++ is perfect 反汇编的工具.
-rockman12(TianTian);
2002-1-28
(#349958@0)
-
我认为没必要.
-netee(netee);
2002-1-27
(#349466@0)
-
理解一些底层的东西有助于COMPLICATED CONCEPT的理解.FOR EXAMPLE 通过汇编你将觉得C++多态是如此的容易和如此的具有创新性.理解一些底层的东西有助于COMPLICATED CONCEPT的理解.FOR EXAMPLE 通过汇编你将觉得C++多态是如此的容易和如此的具有创新性.
Hope every c++ programmer to agree with my views.I believe you'll get good benefits by the way.
-rockman12(TianTian);
2002-1-28
{216}
(#349632@0)