LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2008, 02:27 PM   #1
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Rep: Reputation: 15
c++ : stupid problem (class with no type)


Hi !

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..


Thanks for any help
 
Old 02-26-2008, 03:41 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
What namespace is Mesh in?
 
Old 02-26-2008, 03:47 PM   #3
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
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...
 
Old 02-26-2008, 03:50 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
If it’s in the global namespace, try
Code:
protected :
    ::Mesh *mesh;
 
Old 02-26-2008, 04:19 PM   #5
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
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)

I hope I have not a little syntax error somewhere else and the compiler is bullshiting me ^^
 
Old 02-26-2008, 04:22 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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

Last edited by ta0kira; 02-26-2008 at 04:59 PM.
 
Old 02-26-2008, 04:26 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by Shautieh View Post
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.

Last edited by ta0kira; 02-26-2008 at 04:27 PM.
 
Old 02-26-2008, 04:51 PM   #8
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
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..

Thanks for the help everyone
 
Old 02-26-2008, 04:56 PM   #9
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
So is this working now? If not do you have a repository you can point to?
 
Old 02-26-2008, 05:14 PM   #10
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
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 ^_^
 
Old 02-26-2008, 05:19 PM   #11
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by Shautieh View Post
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.
Code:
//file1.h
#ifndef file1_h
#define file1_h

//...

#endif
Code:
//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
ta0kira

Last edited by ta0kira; 02-26-2008 at 05:21 PM.
 
Old 02-26-2008, 05:40 PM   #12
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
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
 
Old 02-26-2008, 06:50 PM   #13
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
See if you can compile this:
Code:
#include <Mesh.h>

namespace HES
{
::Mesh *mesh;
}
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

Last edited by ta0kira; 02-26-2008 at 06:51 PM.
 
Old 02-26-2008, 07:11 PM   #14
Shautieh
Member
 
Registered: Sep 2006
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: 15
With just this I get :
Code:
 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
Don't mind the French comments ;p
 
Old 02-26-2008, 07:58 PM   #15
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ templated Node class: pointers to different instantated class types jhwilliams Programming 3 08-20-2007 06:20 PM
Identify class type Ephracis Programming 1 05-05-2007 09:03 AM
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM
Which C++ editor in Linux has the class view/class browser feature imaginationworks Programming 7 05-21-2006 11:09 PM
c++ list class, type of node? exodist Programming 2 05-20-2004 06:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration