I have two classes, Mesh and MeshList. I want MeshList to have a function that can change the private members of Mesh. But it won't compile and I don't know why. Here's my code.
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;
}
I get these errors:
MeshList.h (Line 11)
- error C2143: syntax error : missing ';' before '*'
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
mesh.h(11) : error C2653: 'MeshList' : is not a class or namespace name
- meshlist.cpp(5) : error C2248: 'Mesh::vboHandle_' : cannot access private member declared in class 'Mesh'
- mesh.h(10) : see declaration of 'Mesh::vboHandle_'
- mesh.h(8) : see declaration of 'Mesh'
- meshlist.cpp(5) : error C2100: illegal indirection
class Meshlist;
instead of#include "MeshList.h"
– chrisMeshList
a forward declaration does not cut it. – Matthieu M.