使用字符串时,C++未知重写说明符

C++ unknown override specifier when using strings

本文关键字:未知 重写 说明符 C++ 字符串      更新时间:2023-10-16

我已经尝试解决这个问题很长时间了:

我有以下课程(医生):

医生:

    #pragma once
    class Doctor
    {
    private:
         string firstName;
    public:
        Doctor();
        ~Doctor();
    };

博士.cpp:

    #include "stdafx.h"
    #include "string"
    #include "Doctor.h"
    using namespace std;
    Doctor::Doctor()
    {
    }

    Doctor::~Doctor()
    {
    }

以及我的主要功能:

   #include "stdafx.h"
   #include <string>
   #include "Doctor.h"
   using namespace std;
   int main()
   {
       return 0;
   }

错误C3646"firstName":未知的重写说明符

错误C4430缺少类型说明符-假定为int。注意:C++不支持默认的int

错误C3646"firstName":未知的重写说明符

错误C4430缺少类型说明符-假定为int。注意:C++不支持默认的int

在Doctor.h的第5行,我声明了一个字符串变量

也许

<string> header is missing.

尝试包含它。

Dr.h

#ifndef DOCTOR_H_
#define DOCTOR_H_
#include <string>
class Doctor{
    std::string name;
public:
    Doctor();
    ~Doctor();
};
#endif

博士.cpp

#include "Doctor.h"
Doctor::Doctor()
{
}
Doctor::~Doctor()
{
}

主要.cpp

#include "Doctor.h"
int main()
{
    return 0;
}

它运行良好。我已经测试过了。

您需要Doctor.h中的#include <string>,并且需要标准命名空间std::string