Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1103877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:24:14+00:00 2026-05-17T01:24:14+00:00

I’m receiving the forbids declaration without type error in a Qt application I’m working

  • 0

I’m receiving the forbids declaration without type error in a Qt application I’m working on. The problem is that I have included the header file which declares the class. It should be defined as a type as far as I can tell. I tried forward declaration as well, but I’d like to use the methods of the class in this file and so I need the whole header file.
code:

Shapes.h

#ifndef SHAPES_H
#define SHAPES_H

#include "Colors.h"
#include <QPoint>
#include "glwidget.h"

//class GLWidget;  

class Shape
{
    public:

        virtual void draw();
};

class Rectangle : public Shape
{
    public:
        Rectangle(GLWidget *w, QPoint tl, QPoint br);

        virtual void draw(){
              // top horizontal
            for(int i = topLeft.x(); i < btmRight.x(); i++){
                 glWidget->setPixel(i,topLeft.y(), color);
             }
        }

    private:
        QPoint topLeft,btmRight;
        GLWidget *glWidget;        /****  This is the Error line  ****/
        RGBColor color;
};

#endif // SHAPES_H

glwidget.h:

#ifndef AGLWIDGET_H
#define AGLWIDGET_H

#include <QGLWidget>

#include "Colors.h"
#include "Shapes.h"

class GLWidget : public QGLWidget
{
    Q_OBJECT

public:
    GLWidget(QWidget *parent = 0);
    ~GLWidget();

    QSize minimumSizeHint() const;
    QSize sizeHint() const;

    void setPixel(int x, int y, RGBColor c);

public slots:
    void setColor(RGBColor c);
    void setDrawRectangle();



protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

private:

    QPoint lastPos;
    QVector<QPoint> drawPoints;
    RGBColor paintColor;
    int drawmode;
    Shape *currentShape;

};


#endif

I don’t see why I can’t use my GLWidget in Shapes.h. The error is in Shapes.h on the line where I declare GLWidget *glWidget;
If I use a forward declaration ie. class GLWidget; this error goes away but then I can’t actually use the GLWidget methods as in Rectangle.draw()

Anyone have an idea why the compiler wouldn’t see GLWidget as a type in Shapes.h?

Exact errors:

Shapes.h:20: error: expected ‘)’ before ‘*’ token
Shapes.h:31: error: ISO C++ forbids declaration of ‘GLWidget’ with no type
Shapes.h:31: error: expected ‘;’ before ‘*’ token
Shapes.h: In member function ‘virtual void Rectangle::draw()’:
Shapes.h:25: error: ‘glWidget’ undeclared (first use this function)
Shapes.h:25: error: (Each undeclared identifier is reported only once for each function it appears in.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:24:14+00:00Added an answer on May 17, 2026 at 1:24 am

    You have a circular dependency between your header files — Shapes.h includes glwidget.h, which includes Shapes.h again. So, the second time the compiler tries to include glwidget.h, the include guard AGLWIDGET_H has been defined, so it doesn’t include it again, and then the code in Shapes.h tries to use types that ought to have been declared but are not.

    To fix it, you need to remove one of the dependencies and use forward declarations instead. Since glwidget.h doesn’t actually use the Shape class beyond declaring a pointer member variable, you should remove its inclusion of Shapes.h:

    glwidget.h:

    #ifndef AGLWIDGET_H
    #define AGLWIDGET_H
    
    // do NOT include Shapes.h
    
    class Shape;  // forward declaration
    
    class GLWidget : public QGLWidget
    {
        ...
        Shape *currentShape;
    };
    
    #endif
    

    Shapes.h is the same as before:

    #ifndef SHAPES_H
    #define SHAPES_H
    
    #include "glwidget.h"
    ...
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.