这不是一个很大的问题,但是我想知道当涉及类中的 friend 功能时,IntelliSense是否被搞砸了?

我有一个使用重载运算符处理ostream和istream(<>)的类,并且将它们标记为类中的 friend 函数。因此,从理论上讲,他们应该可以访问类(class)的私有(private)成员。该程序可以编译并正常运行,没有错误-但是随着我继续编写代码,IntelliSense不断报告成员功能对函数来说不可访问。它仍然可以编译,但是我想知道这是否是IntelliSense的问题,或者到底是什么问题,我只是很幸运地发现它正在运行?

    friend std::ostream & operator <<(std::ostream &, const Rational &);
    friend std::istream & operator >>(std::istream &, Rational &);

    std::ostream & operator <<(std::ostream & outs, const Rational & source)
    {
        outs << source.itsNum << '/' << source.itsDen;
        return outs;
    }

    std::istream & operator >>(std::istream & ins, Rational & target)
    {
        ins >> target.itsNum >> target.itsDen;
        return ins;
    }

最佳答案

您的代码没有错。我敢打赌,IntelliSense搞砸了。尝试删除项目的IntelliSense数据库,以查看错误是否会消失(在Visual Studio重新启动后,IntelliSense数据库将自行重建)。该数据库应位于.sln文件旁边,并且(至少对于Visual Studio 2008而言)具有扩展名.ncb

除此之外,还有一些其他信息。 VisualStudio AFAIK的IntelliSense功能实际上是由Microsoft以外的公司开发的,因此编译器和IntelliSense有时可能对正确和不正确有不同的看法。只是说。 :)

关于c++ - IntelliSense和 friend 函数错误错误(VS2010),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12209052/

10-11 23:14
查看更多