ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I must have done something silly, but I just can't see it *_*
I have this error :
Quote:
ISO C++ forbids declaration of «Mesh" with no type
which is usually seen when we forget to include the class header or make a forward declaration, and well, this stuff is supposed to be included...
I am guessing it is the namespace which causes me this problem but I can't find the (obvious ?) solution (I am still a n00b concerning namespaces). Here is the code :
Code:
#ifndef HE_VERTEX_H
#define HE_VERTEX_H
#include <vector>
#include <map>
#include <iostream>
#include <Mesh.h> // should be OK, and it doesn't help if I give the relative path
#include <Vector3.h>
namespace HES
{
class HE_Vertex
{
friend class Mesh; <=== NO error here
protected :
Mesh *mesh; <=== error here
public :
// methods and etc.
}; // End of class
inline methods ...
} // End of namespace HES
#endif
Of course the class Mesh is defined in Mesh.h, and works elsewhere..
It isn't in a specific namespace. Do you think this is the problem ? I already tried to put a "Vector3 *v;" before "Mesh *mesh" to see if their non belonging to the HES namespace was a problem but the error still was on Mesh...
Notice it says that Mesh has no type, not mesh. What happens if you comment out the friend line? What if you leave the friend line and comment the Mesh *mesh line? Do you use mesh anywhere else?
ta0kira
I tried that too but the problem remained. It also says "invalid use of ::"
Notice it doesn't complain about "friend class Mesh;", but it does with "friend class ::Mesh;" («Mesh" in namespace «::" does not name a type)
That means Mesh hasn't ever been declared. It takes it without :: because without it that makes it an implicit declaration of Mesh, but with it it looks for an actual declaration and doesn't find one. Add the line class Mesh; right above namespace HES and see what happens.
ta0kira
Edit: Better yet, make that line class Mesh {};. If that doesn't give you an error then Mesh isn't included in the current file.
The only errors I have then are in my inline functions as I use methods from the Mesh class... So, how can Mesh not be included in the current file ?
Mesh.h is in the reportory "entities", which is in the "include paths" and is used elsewhere without any problems ! And if I include "../../entities/Mesh.h" it doesn't help (that was the first thing I tried)
It would tell me if the file didn't exist anyway..
It doesn't work : the forward declaration makes it so I don't have the error for "Mesh *mesh;" but I still have it for my inline functions as the file doesn't seem to be included (as tah0kira said it should make an error at the forward declaration stage).
There is no repository, but I could quote more code here if you want
PS : Given how it is now, I guess it would work if I put my inline functions as normal functions in my cpp so I only need to put a forward declaration in the header file, but I'd like to know what's wrong anyway ^_^
PS : Given how it is now, I guess it would work if I put my inline functions as normal functions in my cpp so I only need to put a forward declaration in the header file, but I'd like to know what's wrong anyway ^_^
Are you using header locks in 'Mesh.h'? Maybe you accidentally copied an old header when making a new one and didn't change the lock name.
//file2.h
#ifndef file1_h
#define file1_h
//this stuff doesn't get included if 'file1.h' is included first
#include "file1.h" //'file1.h' won't get included
#endif
Good question, though I verified and it's all good (_MESH_H_ (the header lock) is found only in the Mesh.h file).
Just in case you see something wrong as it was the first time I used forward declaration of classes inside a namespace :
in Mesh.h :
Code:
#ifndef _MESH_H_
#define _MESH_H_
#include "Entity.h"
#include <vector>
#include <map>
#include <HalfEdgeStructure.h>
#include "Vertex.h"
namespace HES {
class HalfEdgeStructure;
class HE_Face;
class HE_Vertex;
}
class Mesh : public Entity
{
friend class HES::HalfEdgeStructure;
friend class HES::HE_Face;
friend class HES::HE_Vertex;
...
}; // end class
#endif
If that doesn't work then you know where the problem is (or at least the header to redirect your search to.) Next, add #include <Vector3.h> right after #include <Mesh.h>. If both work then you're probably excluding important information from your example header.
ta0kira
expected constructor, destructor, or type conversion before «*" token
As for the include Vector3.h, it is already right after the Mesh.h one... (and putting it before Mesh.h doesn't help. They are not directly related anyway).
Here is the complete HE_Vector.h file in case I excluded too much infos :
Code:
#ifndef HE_VERTEX_H
#define HE_VERTEX_H
#include <vector>
#include <map>
#include <iostream>
#include <Vector3.h>
#include <Mesh.h>
//#include "HalfEdge.h"
namespace HES
{
class HalfEdge;
class HE_Vertex
{
friend class Mesh;
protected :
//! Mesh to work on
Mesh *mesh;
//! index du sommet dans le tableau opengl de sommets correspondant à celui-ci.
unsigned int indexGL;
//! pointeur vers une demi-arête sortante
HalfEdge *outHE;
public:
/*! Constructor */
HE_Vertex (Mesh *mesh, unsigned int indexGL = 0);
/*! Destructor */
~HE_Vertex() {}
Vector3& getMyCoords() const;
Vector3& getMyNormal() const;
HalfEdge *getOutHE() const;
unsigned int getIndexGL() const;
void setMyNormal(Vector3 *myNewNormal, unsigned int indexGL);
void setMyCoords(Vector3 *myNewCoords, unsigned int indexGL);
void setOutHE(HalfEdge *newOutHE);
void setIndexGL(unsigned int index);
/* surcharge de l'operator<< */
friend std::ostream& operator<<(std::ostream& o, const HE_Vertex &v);
/* Méthode qui permet de trouver toutes les demi-arêtes sortantes d'un sommet */
std::vector<HalfEdge*> &getAllOutHE() const;
bool operator== (const HE_Vertex &v) const;
bool operator!= (const HE_Vertex &v) const;
};
/*! Définition des méthodes inline */
inline Vector3& HE_Vertex::getMyCoords() const {
return this->mesh->getCoords(indexGL);
}
inline Vector3& HE_Vertex::getMyNormal() const {
return this->mesh->getNormal(indexGL);
}
inline HalfEdge *HE_Vertex::getOutHE() const {
return this->outHE;
}
inline unsigned int HE_Vertex::getIndexGL() const {
return this->indexGL;
}
inline void HE_Vertex::setMyCoords(Vector3 *myNewCoords, unsigned int indexGL) {
this->mesh->setCoords(myNewCoords, indexGL);
}
inline void HE_Vertex::setMyNormal(Vector3 *myNewNormal, unsigned int indexGL) {
this->mesh->setNormal(myNewNormal, indexGL);
}
inline void HE_Vertex::setOutHE(HalfEdge *newOutHE) {
this->outHE = newOutHE;
}
inline void HE_Vertex::setIndexGL(unsigned int index) {
this->indexGL = index;
}
} // namespace HES
#endif // HE_VERTEX_H
Try commenting out the entire class body of Mesh in Mesh.h. It will make your inlines fail, but it will tell you if the problem is there or not.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.