Results 1 to 3 of 3

Thread: In spite of #including the header files I get: "... was not declared in this scope"

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default In spite of #including the header files I get: "... was not declared in this scope"

    Hi,
    I am writing an application consisting of some files that do inherit from a common base class "Piece". When I try to instantiate an object based on "Piece" inside another class that is also based on "Piece" I get an error like this: "... was not declared in this scope".
    I can however instantiate objects from these classes inside other non-related classes. Creating a minimal compilable piece of code to highlight that problem would involve changing the whole code base (bad design :-s) so I just wanted to know if anybody here is able to quickly spot the problem. you can get the sources from here: http://gitorious.org/shatranj/shatranj/trees/master (There is a Download master as tar.gz button on the right side of the page.) Compiling it involves: qmake && make


    Here is a piece of code that highlights the problem in "king.cpp"

    Qt Code:
    1. #include "king.h"
    2. #include "chessboard.h"
    3.  
    4. // Qt
    5. #include <QPair>
    6. #include <QDebug>
    7.  
    8. #include "rook.h"
    9.  
    10. King::King(ChessBoard const* board, Color color, int file, int rank)
    11. : Piece(board, Piece::King, color, file, rank)
    12. , m_hasMoved(false)
    13. {
    14. Rook* r;
    15. }
    16.  
    17. ...
    To copy to clipboard, switch view to plain text mode 

    If you remove Rook* r; the code will compile without any further issues. Can anybody tell me what I am doing wrong?

    Thanks in advance

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: In spite of #including the header files I get: "... was not declared in this scop

    King inherits Piece which has enum containing Root enum. I wonder which the compiler takes when you use "Rook *r".

    May change the enum say it says instead ID_Rook, etc to prevent collisions with classes of the same name.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Smile Re: In spite of #including the header files I get: "... was not declared in this scop

    Thanks alot :-).

Similar Threads

  1. Implementing an "open recently opened files" menu?
    By joelthelion in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2009, 10:49
  2. qx11embed_x11.h: "XEvent" has not been declared
    By crazymoonboy in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 18th September 2008, 02:30
  3. Replies: 8
    Last Post: 5th August 2008, 12:09
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.