Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown type error in C++

Tags:

c++

xcode

cinder

What is going on?

#include "MyClass.h"

class MyOtherClass {
  public:
    MyOtherClass();
    ~MyOtherClass();

    MyClass myVar; //Unknown type Error
};

Suddenly when I include the .h and write that var Xcode gives me tons of errors... and also the unknown type error.

How can it be unknown when the .h is included right there?

Here is the NodeButton.h file which would correspond to the MyClass.h in the example

#pragma once

#include "cinder/Vector.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/Texture.h"
#include "cinder/Color.h"
#include "cinder/ImageIo.h"
#include "cinder/Timeline.h"
#include "cinder/app/AppBasic.h"
#include "cinder/App/App.h"

#include "Node.h"
#include "CursorMano.h"

using namespace ci;
using namespace ci::app;
using namespace std;
using namespace is;

typedef boost::shared_ptr<class NodeButton> NodeButtonRef;


class NodeButton  : public Node2D 
{
    public:
        NodeButton (CursorMano *cursor, string imageUrl, bool fadeIn = false, float delay = 0.0f);
        virtual ~NodeButton ();

        //methods
        void update( double elapsed );
        void draw();
        void setup();

        //events
        bool mouseMove( ci::app::MouseEvent event );

        //vars
        CursorMano      *mCursor;
        gl::Texture     mImageTexture;
        Anim<float>     mAlpha = 1.0f;
        bool            mSelected = false;

    private:
};

And here are the contents of CursorMano.h which would correspond to MyOtherClass.h in the example.

#pragma once

#include <list>
#include <vector>

#include "cinder/app/AppBasic.h"
#include "cinder/qtime/QuickTime.h"
#include "cinder/gl/Texture.h"
#include "cinder/Vector.h"

#include "NodeButton.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class CursorMano {
    public:
        CursorMano (AppBasic *app);
        ~CursorMano ();

        void    mueveMano(Vec2i);
        void    update();
        void    draw();
        void    play(int button);
        void    reset(int button);

        Vec2i   mMousePos;
        NodeButton                  mButtonCaller; //this gives the unknow type error

    private:
        AppBasic                    *mApp;
        gl::Texture                 mFrameTexture;
        qtime::MovieGl              mMovie;
        int                         mIdButton;
};
like image 213
Pier Avatar asked Mar 30 '26 00:03

Pier


2 Answers

You have a circular dependency of your header files.

NodeButton.h defines NodeButton class which CursorMano.h needs to include so that compiler can see definition for NodeButton but NodeButton.h itself includes CursorMano.h.

You will need to use forward declarations to break this circular dependency.

In NodeButton.h you just use an pointer to CursorMano so You do not need to include the CursorMano.h just forward declare the class after the using namespace declarations.

using namespace std;
using namespace is;

class CursorMano;
like image 54
Alok Save Avatar answered Apr 03 '26 00:04

Alok Save


It's probably a result of the circular dependency between you two header files (NodeButton includes CursorMano and CursorMano includes NodeButton). Try removing the #include "CursorMano.h" in NodeButton.h and add class CursorMano; before your NodeButton declaration.

like image 34
kevintodisco Avatar answered Apr 02 '26 23:04

kevintodisco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!