无法确定IDE为什么在C ++中说未声明的标识符 [英] Trouble with identifying why the IDE is saying undeclared identifier in C++

查看:86
本文介绍了无法确定IDE为什么在C ++中说未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有这些代码行的类.我正在苦苦挣扎的是写函数,因为我的IDE提示对根使用未声明的标识符"

I have a class at the moment with these lines of code. What I am struggling with is the function write in that my IDE says "Use of undeclared identifier for 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);
    }

编辑以使用模板显示更多完整的代码.

Edit to show more full extent of the code with the Template.

推荐答案

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

Try using the scope resolution operator to tell the compiler that your write function belongs to class X:

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

模板
使用模板,语法变为:

Edit 1: templates
With templates, the syntax becomes:

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

这篇关于无法确定IDE为什么在C ++中说未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆