C++ 指针机制 - 错误 2440

标签 c++ visual-c++ compiler-errors

<分区>

Possible Duplicate:
Conversion of pointer-to-pointer between derived and base classes?
Converting Derived** to Base** and Derived* to Base*

我有一个 intf + 类

class IList
{
public:
    virtual IList** GetChildList()=0;
    virtual void SetChildList(IList**)=0;
    ~IList();
};

class CList:public IList
{
    CList** m_lst;
public:
    IList** GetChildList()=0;
    virtual void SetChildList(IList**);
//...
};

IList** CList::GetChildList()
{
    return m_lst;
}

为什么我在 MSVC 中的 GetChildList 中收到错误 2440,提示“'return':无法从 'CList** **' 转换为 'IList **”

提前感谢您的帮助!

最佳答案

CList 派生自IList,因此您可以将CList* 转换为IList*。但是,您不能将 CList** 转换为 IList**。你需要一个 reinterpret_cast。

关于C++ 指针机制 - 错误 2440,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877023/

相关文章:

compiler-errors - make - 编译 modowa (apache-module) 时出现 fatal error

c++ - 将非常量 c 字符串读入字符串类

python - 如何使用 CUDA CURAND 保存和恢复随机数生成器的状态?

c++ - 我可以让 VC++ Intellisense 忽略一些它认为无效的东西吗?

c++ - 尝试构建 Skia 时缺少头文件

compiler-errors - 在我的Triangle类中找不到符号错误

c++ - "char *"和 "String"函数的返回类型是否相同?

c++ - 使用 CSerial (C++) 打开虚拟 COM 端口

c++ - Visual C++ 2010 - fatal error LNK1169 : one or more multiply defined symbols found

java - main将在哪里实现,以便程序在此代码中执行?