无法确定 IDE 在 C++ 中说出未声明标识符的原因

Trouble with identifying why the IDE is saying undeclared identifier in C++

本文关键字:标识符 未声明 IDE C++ 无法确定      更新时间:2023-10-16

我现在有一个带有这些代码行的类。我正在努力的是我的IDE说"使用root的未声明标识符"的功能写入

这是为什么呢?

template<typename T>
    class X
    {
    public:
        const void write(std::ostream & output);
    private:
        std::unique_ptr< TreeNode<Ty> > root;

    };

    const void write(std::ostream & output)
    {
        root->write(output);
    }

编辑以显示模板代码的更完整范围。

尝试使用范围解析运算符告诉编译器您的write函数属于class X

const void X::write(std::ostream & output)
{
    root->write(output);
}

编辑 1:模板
使用模板,语法变为:

template<typename T>
const void
X<T>::write(std::ostream & output)
{
    root->write(output);
}