gpt4 book ai didi

c++ - 前向声明来自不同命名空间的抽象类

转载 作者:行者123 更新时间:2023-11-28 07:53:44 33 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
The type in a dynamic_cast must be a pointer or reference to a complete class type, or void *

我有一个命名空间 Fuzzy,它有一个名为 CuteDog 的抽象类(继承自另一个抽象类)。

我正在编写一个名为 PuppyArmy 的新类

我想在 PuppyArmy 和我的头文件中有一个指向 CuteDog 的指针,我正在尝试这个。

namespace Fuzzy { class CuteDog }

using namespace Fuzzy;

class PuppyArmy {
...
CuteDog *cute;
}

然后在我的 cpp 文件中我得到了这个

using namespace Tough;

....
cute = dynamic_cast<::Fuzzy::CuteDog*>(foo()); // where foo() returns the parent class of CuteDog*

编译器告诉我

 C2440: '=' : cannot convert from Fuzzy::CuteDog * to PuppyArmy::Fuzzy::CuteDog *

有没有指出我在这里做错了什么?

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