小编use*_*003的帖子

C++重写的虚函数未被调用

我有以下设置:

main.cpp中:

int main()
{
    vector <Tour> tourList;
    Tour* tour_ptr;

    for (unsigned int i = 0; i < tourList.size(); i++)
    {
        tour_ptr = &tourList[i];
        tour_ptr->display();
    }
}
Run Code Online (Sandbox Code Playgroud)

Tour.h:

class Tour
{
   public:
    virtual void display();
};
Run Code Online (Sandbox Code Playgroud)

Tour.cpp:

void Tour::display()
{
    cout << "Tour ID: " << getID() << "\n";
    cout << "Description: " << getdescription() << "\n";
    cout << "Tour Fee: $" << getfee() << "\n";
    cout << "Total Bookings: " << getbookings() << "\n\n";
}
Run Code Online (Sandbox Code Playgroud)

GuidedTour.h:

class GuidedTour : …
Run Code Online (Sandbox Code Playgroud)

c++

7
推荐指数
2
解决办法
6209
查看次数

我的功能不能正确编译

尝试编译以下函数时出现以下错误:

Error: invalid operands of types int and const char [3] to binary operator
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

string getFormattedDate()
{
    formattedDate = Date.getDay() << "/" << Date.getMonth() << "/" << Date.getYear();
    return formattedDate;
}
Run Code Online (Sandbox Code Playgroud)

c++ string

0
推荐指数
1
解决办法
127
查看次数

标签 统计

c++ ×2

string ×1