简体   繁体   中英

C++ Class constructor confusion

I have 2 files, Chrono.cpp and Chrono.h.

Chrono.h

class Appointment {
public:

    Appointment( Date d , string n ) ;
    Appointment() ;

    int get_day() const { return date.d; }
    int get_month() const { return date.m; }
    int get_year() const { return date.y; }
    string get_name() const { return name ; }

    Date date ;
    string name ;

} ;

Chrono.cpp

Appointment::Appointment( Date dd , string nn )
    : date( dd ) , name( nn ) 
{ 
    //if(!is_date(yy,mm,dd))throw Invalid(); 
}

I continue to get this error, or variations of saying it doesnt match the .h file.

Chrono.cpp:17:1: error: prototype for āChrono::Appointment::Appointment(Chrono::Date, String)ā does not match any in class āChrono::Appointmentā
Chrono.h:34:7: error: candidates are: Chrono::Appointment::Appointment(Chrono::Appointment&&)
Chrono.h:34:7: error:                 Chrono::Appointment::Appointment(const Chrono::Appointment&)
Chrono.h:42:2: error:                 Chrono::Appointment::Appointment(Chrono::Date, std::string)
Chrono.h:41:2: error:                 Chrono::Appointment::Appointment()

Both files have #include string and the .cpp file is in the std name space. I have also tried using std::string in the header file. Nothing I have done has worked so far. Any help is appreciated. Also note that Date is defined elsewhere and is working correctly.

You misspelled "String". In your code it says string , but in the error it says String .

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