ISO C++ forbids declaration of 'Rectangle' with no type

Discussion in 'C++' started by Florian Haag, Jan 24, 2007.

  1. Florian Haag

    Florian Haag Guest

    Hello,
    I'm trying to compile a programme which compiles fine under Linux; I'm
    trying it with MinGW G++ 3.4.2:


    Component.h:

    #ifndef COMPONENT_H_
    #define COMPONENT_H_

    #include "../basics/Rectangle.h"

    class Component {
    private:
    Rectangle *bounds;
    // Unique identifier
    long id;

    // more declarations

    };

    #endif


    Rectangle.h (relative path is as included above):

    #ifndef RECTANGLE_H_
    #define RECTANGLE_H_

    #include "Point.h"

    class Rectangle
    {
    // some declarations
    };

    #endif


    Point.h (same directory as Rectangle.h)

    #ifndef POINT_H_
    #define POINT_H_

    class Point {
    // some declarations
    };

    #endif


    Now, in Windows, I always get the following compilation errors (where
    line 25 in Component.h matches the line "Rectangle *bounds;" shown
    above):

    In file included from visdgetsbase.h:13,
    from main.cpp:14:
    widgets/Component.h:25: error: ISO C++ forbids declaration of
    `Rectangle' with n
    o type
    widgets/Component.h:25: error: expected `;' before '*' token
    widgets/Component.h:41: error: ISO C++ forbids declaration of
    `Rectangle' with n
    o type
    widgets/Component.h:41: error: expected `;' before '*' token
    widgets/Component.h:43: error: variable or field `setBounds' declared
    void
    widgets/Component.h:43: error: expected `;' before '(' token

    So, why isn't Rectangle recognized as a type?

    I tried removing the relative path in #include, but that only results
    in an additional error message saying that the file Rectangle.h wasn't
    found at all. I also made sure I don't have any other file called
    Rectangle.h on my entire hard disk, so quite obviously, with the
    relative paths given in the #include directive, the correct file
    should've been found, then why isn't the type Rectangle?

    Thanks in advance,
    Florian
    Florian Haag, Jan 24, 2007
    #1
    1. Advertising

  2. On Jan 24, 1:35 pm, "Florian Haag" <> wrote:
    > Hello,
    > I'm trying to compile a programme which compiles fine under Linux; I'm
    > trying it with MinGW G++ 3.4.2:
    >
    > Component.h:
    >
    > #ifndef COMPONENT_H_
    > #define COMPONENT_H_
    >
    > #include "../basics/Rectangle.h"
    >
    > class Component {
    > private:
    > Rectangle *bounds;
    > // Unique identifier
    > long id;
    >
    > // more declarations
    >
    > };
    > #endif



    > In file included from visdgetsbase.h:13,
    > from main.cpp:14:
    > widgets/Component.h:25: error: ISO C++ forbids declaration of
    > `Rectangle' with no type


    Seems to me like the problem might be on line 25 in Component.h (or a
    bit above), but the part from Component.h you pasted does not contain
    the 25th line so I can't help you. Make sure that the last statement
    above line 25 has a ; at the end.

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Jan 24, 2007
    #2
    1. Advertising

  3. Florian Haag

    Florian Haag Guest

    Erik Wikström wrote:

    > Seems to me like the problem might be on line 25 in Component.h (or a
    > bit above), but the part from Component.h you pasted does not contain
    > the 25th line so I can't help you. Make sure that the last statement
    > above line 25 has a ; at the end.


    Hi,
    sorry if I explained this in a confusing way, actually, the line

    Rectangle *bounds;

    _is_ line 25, already shown in my code in the original posting (I
    removed some comments when copying the code here).

    Regards, thanks in advance,
    Florian
    Florian Haag, Jan 24, 2007
    #3
  4. Florian Haag

    Kai-Uwe Bux Guest

    Florian Haag wrote:

    > Erik Wikström wrote:
    >
    >> Seems to me like the problem might be on line 25 in Component.h (or a
    >> bit above), but the part from Component.h you pasted does not contain
    >> the 25th line so I can't help you. Make sure that the last statement
    >> above line 25 has a ; at the end.

    >
    > Hi,
    > sorry if I explained this in a confusing way, actually, the line
    >
    > Rectangle *bounds;
    >
    > _is_ line 25, already shown in my code in the original posting (I
    > removed some comments when copying the code here).


    Well, in removing that code, you probably removed the error. Post those
    lines. (This is covered in the FAQ:

    www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 24, 2007
    #4
  5. Florian Haag

    Florian Haag Guest

    Kai-Uwe Bux wrote:

    > Well, in removing that code, you probably removed the error. Post
    > those lines. (This is covered in the FAQ:
    >
    > www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8


    Sorry, this sent me to the right direction; there was a naming conflict
    with a Rectangle-function from wingdi.h, which of course only occurred
    in Windows.
    I'm sorry for not having followed those rules, I still am not used that
    in C++, there can be such an influence accross several files, unlike in
    some other languages.

    Regards,
    Florian
    Florian Haag, Jan 24, 2007
    #5
  6. Florian Haag

    Bo Persson Guest

    Florian Haag wrote:
    > Kai-Uwe Bux wrote:
    >
    >> Well, in removing that code, you probably removed the error. Post
    >> those lines. (This is covered in the FAQ:
    >>
    >> www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    >
    > Sorry, this sent me to the right direction; there was a naming
    > conflict with a Rectangle-function from wingdi.h, which of course
    > only occurred in Windows.
    > I'm sorry for not having followed those rules, I still am not used
    > that in C++, there can be such an influence accross several files,
    > unlike in some other languages.
    >


    So C++ provides namespaces to isolate different components into their own
    space.


    Bo Persson
    Bo Persson, Jan 24, 2007
    #6
  7. Florian Haag

    Noah Roberts Guest

    On Jan 24, 6:24 am, "Florian Haag" <> wrote:
    > Kai-Uwe Bux wrote:
    > > Well, in removing that code, you probably removed the error. Post
    > > those lines. (This is covered in the FAQ:

    >
    > > www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8Sorry, this sent me to the right direction; there was a naming conflict

    > with a Rectangle-function from wingdi.h, which of course only occurred
    > in Windows.
    > I'm sorry for not having followed those rules, I still am not used that
    > in C++, there can be such an influence accross several files, unlike in
    > some other languages.


    Other languages usually solve this "problem" with namespaces. It is
    rare that a language allows the same symbol to be used to mean
    different things.
    Noah Roberts, Jan 24, 2007
    #7
  8. Florian Haag

    Florian Haag Guest

    Noah Roberts wrote:

    > > I'm sorry for not having followed those rules, I still am not used
    > > that in C++, there can be such an influence accross several files,
    > > unlike in some other languages.

    >
    > Other languages usually solve this "problem" with namespaces. It is
    > rare that a language allows the same symbol to be used to mean
    > different things.


    Right, well - e.g. in Delphi, if you include another source file A, by
    default, you just include the declarations from that very source file
    A, not those of other source files B and C referenced by A.

    Regards,
    Florian
    Florian Haag, Jan 24, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik S. Hansen
    Replies:
    2
    Views:
    51,458
    Alf P. Steinbach
    May 2, 2004
  2. Penn
    Replies:
    4
    Views:
    1,370
    =?ISO-8859-1?Q?Sch=FCle_Daniel?=
    Jan 9, 2006
  3. gamehack
    Replies:
    3
    Views:
    8,106
    gamehack
    Feb 13, 2006
  4. Replies:
    7
    Views:
    831
    red floyd
    Feb 5, 2008
  5. aneuryzma
    Replies:
    8
    Views:
    1,083
    Puppet_Sock
    Jul 2, 2008
Loading...

Share This Page