我有两个类,Mesh和MeshList。我想让MeshList拥有一个可以改变Mesh私有成员的函数。但是它无法编译,我不知道为什么。这是我的代码。
Mesh.h
#ifndef _MESH_H
#define _MESH_H
#include "MeshList.h"
#include <iostream>
class Mesh
{
private:
unsigned int vboHandle_;
friend void MeshList::UpdateVBOHandle();
public:
inline void Out() {std::cout << vboHandle_;}
};
#endif
Mesh.cpp
#include "Mesh.h"
MeshList.h
#ifndef _MESH_LIST_H
#define _MESH_LIST_H
#include "Mesh.h"
class MeshList
{
public:
Mesh *mesh; //Line 11 Error
void UpdateVBOHandle();
};
#endif
MeshList.cpp
#include "MeshList.h"
void MeshList::UpdateVBOHandle()
{
*mesh->vboHandle_ = 4;
}
我遇到了以下错误:
MeshList.h(第11行)
- 错误 C2143:缺少“;”(分号)
- 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认 int
错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认 int
mesh.h(第11行):错误 C2653:“MeshList”不是类或命名空间名称
- meshlist.cpp(第5行):错误 C2248:“Mesh::vboHandle_”无法访问在类“Mesh”中声明的私有成员
- mesh.h(第10行):请参见“Mesh::vboHandle_”的声明
- mesh.h(第8行):请参见“Mesh”的声明
- meshlist.cpp(第5行):错误 C2100:非法的间接引用
class Meshlist;
替代#include "MeshList.h"
。 - chris