首页 > 解决方案 > 由于未声明的标识符,朋友功能将无法工作

问题描述

这是 Foo.hpp

#ifndef Foo_hpp
#define Foo_hpp

#include <stdio.h>
#include "Bar.hpp"

class Bar;

class Foo
{
private:
   int z;
public:
   void addY(Bar &x);
};
#endif /* Foo_hpp */

这是 Bar.hpp

#ifndef Bar_hpp
#define Bar_hpp

#include <stdio.h>
#include "Foo.hpp"

class Bar
{
private:
    int y;
public:
    friend void Foo::addY(Bar&);//use of undeclared identifier 'Foo'
};
#endif /* Bar_hpp */

我什至不知道为什么它一直给我这个错误,我尝试处理它并尝试查看我是否拼写错误或输入错误。我什至尝试从头开始重写所有内容,但仍然出现相同的错误。

标签: c++friend

解决方案


推荐阅读