gpt4 book ai didi

C++ 如何为基类转换对象调用纯虚拟方法?

转载 作者:行者123 更新时间:2023-11-28 03:34:14 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why does an overridden function in the derived class hide other overloads of the base class?

你好,

让我用这个例子来解释我的问题:

class A
{
virtual ~A() = 0 { }

A(const A&);
virtual void operator =(const A&) = 0;
}

class B : public A
{
~B();

B(const B&);
void operator =(const B&);
}

void main(void)
{
A* a = new B();
delete a; // Is ~A() called, ~B() or both ?
}

这让我想问两个问题:

  1. 在抽象基类指针上使用 delete 时调用哪个析构函数?
  2. 是否可以使用上述复制方法之一复制我的对象“a”?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com