繁体   English   中英

C++类构造函数混淆

[英]C++ Class constructor confusion

我有 2 个文件,Chrono.cpp 和 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 ;

} ;

计时文件

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

我继续收到此错误,或者说它与 .h 文件不匹配。

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()

这两个文件都有 #include 字符串,并且 .cpp 文件位于 std 命名空间中。 我也试过在头文件中使用 std::string 。 到目前为止,我所做的一切都没有奏效。 任何帮助表示赞赏。 另请注意,日期是在别处定义的并且工作正常。

你拼错了“字符串”。 在您的代码中它说string ,但在错误中它说String

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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