Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: new types may not be defined in a return type

Tags:

c++

The above error is occurring on the line where I implement my constructor. I made a comment that points to that line. Any help greatly appreciated.

#include <vector>   
#include <time.h>      

class Stopwatch
{
    enum state {UNSTARTED, RUNNING, PAUSED, FINISHED};
    struct time
    {
        unsigned hours;
        unsigned minutes;
        unsigned seconds;
    };
    struct lap
    {
       unsigned n; // lap number
       time t; // lap time
       lap* next_ptr;
    };

    public: 
    Stopwatch();
    ~Stopwatch();
    void right_button(); // corresponds to start/stop/pause
    void left_button();  // corresponds to lap/reset

    private: 
    state cur_state;
    std::vector<lap> lapsvec;

}

Stopwatch::Stopwatch() // <--------- Here's where the compiler error is
{
    cur_state = UNSTARTED;
}

/* trivial destructor */
Stopwatch::~Stopwatch() 
{
}

int main()
{
    return 0;
}

I reviewed C++ constructors to see if I could figure out the problem. No luck.

like image 210
user3566398 Avatar asked Apr 24 '14 23:04

user3566398


1 Answers

You need a ; after the class declaration. Since you don't have it, the class is not yet declared when the compiler reaches Stopwatch::Stopwatch(), thus complaining it's a new type.

like image 159
Paweł Stawarz Avatar answered Nov 15 '22 07:11

Paweł Stawarz