Results 1 to 10 of 10

Thread: 'Class' does not name a type error

  1. #1
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default 'Class' does not name a type error

    hi, its probably some silly mistake in c++ but my code is not working, it gives me error.

    here is code

    _time.h
    Qt Code:
    1. #ifndef _TIME_H
    2. #define _TIME_H
    3.  
    4. #include <QObject>
    5. #include <QTimer>
    6.  
    7. class _Time : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. _Time();
    12. _Time(int sec=0,int min=0,int hour=0);
    13. int hour;
    14. int min;
    15. int sec;
    16. };
    17. #endif // _TIME_H
    To copy to clipboard, switch view to plain text mode 

    _time.cpp
    Qt Code:
    1. #include "_time.h"
    2.  
    3. _Time::_Time()
    4. {
    5.  
    6. hour=0;
    7. min=0;
    8. sec=0;
    9.  
    10. }
    11. _Time::_Time(int s, int m, int h)
    12. {
    13.  
    14. if (h > -1)
    15. hour=h;
    16. else
    17. hour=0;
    18.  
    19. if ((m > -1) && (m<60))
    20. min=m;
    21. else
    22. min=0;
    23.  
    24. if ((s > -1) && (s<60))
    25. sec=s;
    26. else
    27. sec=0;
    28.  
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. #include "_time.h"
    2. _Time t;
    3. int main(int argc, char *argv[])
    4. {
    5.  
    6.  
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    i get error:
    _Time does not name a type.

    any suggestions? thanks in advance
    Last edited by naturalpsychic; 31st January 2011 at 18:34. Reason: code correction
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: 'Class' does not name a type error

    You are missing a semi colon at your class declaration.

  3. #3
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: 'Class' does not name a type error

    thanks for reply but im sorry in actual code there is semi colon (forgot to put in forum)..
    even with semi colon it does not work
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: 'Class' does not name a type error

    naturalpsychic, I have a riddle for you.

    Let us consider following code:

    Qt Code:
    1. _Time t;
    To copy to clipboard, switch view to plain text mode 

    Which one of those two constructors
    Qt Code:
    1. 1) _Time();
    2. 2) _Time(int sec=0,int min=0,int hour=0);
    To copy to clipboard, switch view to plain text mode 
    should be called ?

    Do you know the answer ?

  5. #5
    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: 'Class' does not name a type error

    This exactly what my compiler tells me too.
    Qt Code:
    1. main.cpp:2: error: call of overloaded ‘_Time()’ is ambiguous
    2. _time.h:12: note: candidates are: _Time::_Time(int, int, int)
    3. _time.h:11: note: _Time::_Time()
    4. main.cpp:3: warning: unused parameter ‘argc’
    5. main.cpp:3: warning: unused parameter ‘argv’
    6. make: *** [main.o] Error 1
    To copy to clipboard, switch view to plain text mode 

    You do not need your no-arguments constructor.

    The difference in error messages aside, from the 2003 C++ Standard:
    17.4.3.2.1 Global names [lib.global.names]

    Certain sets of names and function signatures are always reserved to the implementation:

    * Each name that contains a double underscore (_ _) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
    * Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace. [165]

    [165] Such names are also reserved in namespace ::std (17.4.3.1).
    So _Time is a bad name.
    Last edited by ChrisW67; 1st February 2011 at 03:37. Reason: updated contents

  6. #6
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: 'Class' does not name a type error

    thanks for reply

    what i have done now is i changed my '_Time' class name to 'CMTime', thanks for the reference,

    also now i have gotten rid of one of constructor now i have got one constructor,

    i still get this error (CMTime does not name a type)

    and if i get rid of
    #ifndef _TIME_H
    #define _TIME_H

    ...
    #end _TIME_H
    macro definition i get error for multi declaration of class, i had made sure myself by re-writing class with same functions, but its still doing that

    thanks in advance
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: 'Class' does not name a type error

    please send a minimal compilable example reproducing the error.

  8. #8
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: 'Class' does not name a type error

    _time.h
    Qt Code:
    1. #ifndef _TIME_H
    2. #define _TIME_H
    3.  
    4. #include <QObject>
    5. #include <QTimer>
    6.  
    7. class CMTime : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. //CMTime();
    12. CMTime(int sec=0,int min=0,int hour=0);
    13. void startTicking();
    14. QString stop();
    15.  
    16. QString restart();
    17. int getHour();
    18. int getMin();
    19. int getSec();
    20. int getTotalSeconds();
    21. static QString getTime(int h,int m, int s);
    22. private:
    23. QTimer *timer;
    24. int hour;int min;int sec;
    25. signals:
    26. void secondPast(int h,int m,int s);
    27. public slots:
    28. void timeout();
    29.  
    30. };
    31.  
    32. #endif // _TIME_H
    To copy to clipboard, switch view to plain text mode 
    _time.cpp
    Qt Code:
    1. #include "_time.h"
    2.  
    3. /*CMTime::CMTime()
    4. {
    5.   timer=new QTimer(this);
    6.   hour=0;
    7.   min=0;
    8.   sec=0;
    9.   QObject::connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
    10.  
    11. }*/
    12. CMTime::CMTime(int s, int m, int h)
    13. {
    14. timer=new QTimer(this);
    15. if (h > -1)
    16. hour=h;
    17. else
    18. hour=0;
    19.  
    20. if ((m > -1) && (m<60))
    21. min=m;
    22. else
    23. min=0;
    24.  
    25. if ((s > -1) && (s<60))
    26. sec=s;
    27. else
    28. sec=0;
    29.  
    30. QObject::connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
    31. }
    32. int CMTime::getHour()
    33. {
    34. return hour;
    35. }
    36. int CMTime::getMin()
    37. {
    38. return min;
    39. }
    40. int CMTime::getSec()
    41. {
    42. return sec;
    43. }
    44. void CMTime::timeout()
    45. {
    46. emit secondPast(hour,min,sec);
    47. if (sec++ == 59)
    48. {
    49. sec=0;
    50. if (min++ == 59)
    51. {
    52. min=0;
    53. hour++;
    54. }
    55. }
    56.  
    57.  
    58. }
    59.  
    60. QString CMTime::restart()
    61. {
    62. QString result=getTime(getHour(),getMin(),getSec());
    63. sec=0;
    64. hour=0;
    65. min=0;
    66. startTicking();
    67. return result;
    68. }
    69. int CMTime::getTotalSeconds()
    70. {
    71. return (sec + (min * 60) + ((hour * 60) * 60));
    72. }
    73. QString CMTime::getTime(int h,int m,int s)
    74. {
    75. QString resultTime;
    76. QString sStr;QString mStr;QString hStr;
    77. s < 10 ? sStr="0"+QString::number(s):sStr=QString::number(s);
    78. m < 10 ? mStr="0"+QString::number(m):mStr=QString::number(m);
    79. h < 10 ? hStr="0"+QString::number(h):hStr=QString::number(h);
    80.  
    81. resultTime= hStr+ ":"+mStr+":"+sStr;
    82. return resultTime;
    83. }
    84. void CMTime::startTicking()
    85. {
    86. timer->start(1000);
    87. }
    88. QString CMTime::stop()
    89. {
    90. timer->stop();
    91. return getTime(getHour(),getMin(),getSec());
    92. }
    To copy to clipboard, switch view to plain text mode 

    _process.h:
    Qt Code:
    1. #ifndef PROCESS_H
    2. #define PROCESS_H
    3.  
    4. #include <QThread>
    5.  
    6. #include "_time.h"
    7. #include <QTreeWidget>
    8. class CMProcess : public QThread
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit CMProcess(QTreeWidget *parent,QWidget *parentWid);
    13.  
    14.  
    15. CMTime t;//<< here it gives error
    16.  
    17.  
    18. };
    19.  
    20. #endif // PROCESS_H
    To copy to clipboard, switch view to plain text mode 
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

  9. #9
    Join Date
    Mar 2006
    Location
    Mexico City
    Posts
    31
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'Class' does not name a type error

    natural...
    I think you have an error, because I "make" your source code with the changes suggested, and it worked. Maybe you omit making one of the "CM" changes in the class declaration...?
    Hope this helps.

    To late... :-(
    Last edited by arnaiz; 1st February 2011 at 16:47.

  10. #10
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: 'Class' does not name a type error

    oh i solved it myself..just in case you guys wondering i changed header macro name to CMTIME_H

    thanks anyways guys
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

Similar Threads

  1. error ISO C++ forbids declaration of 'obj' with no type
    By naturalpsychic in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2011, 07:23
  2. Replies: 12
    Last Post: 28th May 2010, 01:07
  3. Determine Class Type of QObject Parent
    By photo_tom in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2010, 18:42
  4. Replies: 3
    Last Post: 27th December 2008, 20:34
  5. Data type error
    By MrShahi in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 15:01

Tags for this Thread

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.