Results 1 to 2 of 2

Thread: How to solve "does not name a type error"

  1. #1
    Join Date
    Apr 2014
    Location
    South Africa
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default How to solve "does not name a type error"

    Hi there please help after trying to run the code below I got the error: 'FCType' does not name a type

    header file
    Qt Code:
    1. #ifndef FREIGHTCAR_H
    2. #define FREIGHTCAR_H
    3.  
    4. #include <QString>
    5.  
    6. class FreightCar
    7. {
    8.  
    9. private:
    10. QString ID;
    11. double tonnage;
    12. protected:
    13. enum FCType {ALL, BOX, GONDOLA, TANK, FLATBED};
    14. FCType type;
    15. public:
    16. FreightCar(QString id, double t);
    17. QString getID() const;
    18. double getTonnage();
    19. double setTonnage(double t);
    20. FCType getType() const;
    21. QString toString()const;
    22.  
    23.  
    24.  
    25.  
    26. };
    27. #endif // FREIGHTCAR_H
    To copy to clipboard, switch view to plain text mode 
    .cpp file
    Qt Code:
    1. #include "freightcar.h"
    2.  
    3. FreightCar::FreightCar(QString id, double t)
    4. : ID(id), tonnage(t) { }
    5.  
    6. QString FreightCar::getID() const{
    7. return ID;
    8. }
    9. double FreightCar::getTonnage(){
    10. return tonnage;
    11. }
    12. double FreightCar::setTonnage(double t){
    13. return tonnage = t;
    14. }
    15. FCType FreightCar::getType() const{
    16. return type;
    17. }
    18. QString FreightCar::toString() const{
    19. return QString("Freight car: \nID: %1, %2 \nTonnage: %3 \nFreight car type: %4")
    20. .arg(ID)
    21. .arg(tonnage)
    22. .arg(type);
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 24th April 2014 at 09:44. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to solve "does not name a type error"

    The getType() return type is FreightCar::FCType, there is no FCType in global scope..
    The issue then becomes that the enum is declared protected so it is not useful as the return value of a public function: make the enum declaration public.

    BTW: Your constructor should initialise the type member variable.
    Last edited by ChrisW67; 24th April 2014 at 02:16.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Error Message "Paint device returned engine == 0, type:1"
    By yuzhouzhiwai in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2012, 09:33
  2. Replies: 2
    Last Post: 22nd November 2011, 05:19
  3. Replies: 4
    Last Post: 25th February 2011, 09:01
  4. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 11:45
  5. Compilation error: "field 'xxx' has incomplete type"
    By fedcer in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 15:01

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
  •  
Qt is a trademark of The Qt Company.