简体   繁体   中英

'to_string' unknown override specifier

For an assignment I am supposed to use the following class in a header file 'date.h' However when I attempted to compile my program I got an error stating:

'to_string': unknown override specifier.

What is wrong with the following code? I can't seem to figure it out.

#pragma once
#ifndef DATE_H
#define DATE_H

#include <string>
#include <sstream>

class Date
{
private:
    int m_day, m_month, m_year;
public:
    Date(int d, int m, int y)
    {    
        m_day = d; m_month = m; m_year = y;
    }

    int getDay() const { return m_day; }
    int getMonth() const { return m_month; }
    int getYear() const { return m_year; }
    string to_string() const
    {
        stringstream s;
        s << getMonth() << "/" << getDay() << "/" << getYear();
        return s.str();
    }
};
#endif

it may be because string is part of the standard library. You should do this instead:

std::string to_string() const {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM