0

I have a class:

class MakeMeshStructure : public QObject
{
Q_OBJECT
public:

MakeMeshStructure(QObject* parent = 0) {}

inside one of its functions I do this:

CadPanel * paneli;
int npanelov = mesh.faces_end().handle().idx();
paneli = new CadPanel[npanelov];

and later this:

for(int i=0; i<npanelov;i++){
    if(paneli[i].wasSet)paneli[i].draw(this);
}

this is my panel class:

class CadPanel : public QObject
{

Q_OBJECT
public:

CadPanel();
void draw(MakeMeshStructure* parent); //error here

The error is: Error 27 error C2061: syntax error : identifier 'MakeMeshStructure'

How do I pass MakeMeshStructure parent on to be used in this CadPanel function? Ty

3 Answers 3

4

You must add a forwarding class declaration to your class:

class MakeMeshStructure; // IMPORTANT: Declares a forwarding class

class CadPanel : public QObject 
{

    Q_OBJECT
public:

    CadPanel();
    void draw(MakeMeshStructure* parent); // no more error :)
}

Note that if the classes are in separate namespaces, you must qualify the name with the proper namespace.

Sign up to request clarification or add additional context in comments.

1 Comment

Works! I added class MakeMeshStructure; in both hh and cc.
1

Depending on the use you do of MakeMeshStructure in CadPanel::draw() you may need to include the header containing the definition of MakeMeshStructure:

#include "MakeMeshStructure.h"

or simply make a forward declaration before the definition of CadPanel:

class MakeMeshStructure;
class CadPanel : public QObject
{
...

Comments

1

The reason for your error is because when MakeMeshStructure is being compiled the compiler has no knowledge of the CadPanel class.

Since the MakeMeshStructure method is only using a pointer to CadPanel this problem can be solved using a forward declaration of CadPanel

class MakeMeshStructure; // Forward declaration of MakeMeshStructure

class CadPanel
{
    Q_OBJECT

public:
    CadPanel();
    void draw( MakeMeshStructure* parent );
};

However, if the MakeMeshStructure method created an instance of CadPanel you would be required to include the header within which CadPanel had been defined. This is because in order to create an instance of CadPanel the complete definition of the class is required.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.