mardi 4 mai 2021

C++ C'tor does not initialize fields?

In C++11 I wrote:

JobsList::JobEntry::JobEntry(pid_t pid, pid_t jid, const string &cmd, bool is_stopped) : pid(pid), jid(jid), cmd(cmd),
                                                                                         is_stopped(is_stopped) {
    time(&insertion_time);
}

But the compiler keeps giving me warning:

Clang-Tidy: Constructor does not initialize these fields: insertion_time

How can I get rid of this and initialize in_time?

my class:

class JobsList
{
public:
    class JobEntry
    {
    public:
        pid_t pid, jid;
        string cmd;
        time_t in_time;
        bool is_stopped;

        JobEntry(pid_t pid, pid_t jid, const string &cmd, bool is_stopped);

        bool operator<(JobEntry const &tmp) const {
            return jid < tmp.jid;
        }

        bool operator==(JobEntry const &tmp) const {
            return jid == tmp.jid;
        }
    };
    //Some other code
};

Aucun commentaire:

Enregistrer un commentaire