VS2019 C++未知覆盖说明符

VS2019 C++ unknown override specifier

本文关键字:说明符 覆盖 未知 C++ VS2019      更新时间:2023-10-16

我在使用 VS2019 编译我的C++代码时遇到困难。

我有 Person.h 头文件:

#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
namespace PersonClass {
struct Person {
public:
Name name;
int age;
};
struct Name {
public:
string firstName;
string lastName;
};
}
#endif

这是我的主要.cpp:

#include "pch.h"
#include <iostream>
#include "Person.h"
using namespace std;
int main()
{
return 0;
}

当我编译此文件时,出现以下错误:

  1. "name":未知覆盖说明符缺少类型说明符 - int 假设。
  2. 注意:C++不支持默认整数

有人可以教我如何解决这个问题吗?

当您尝试使用它时,尚未定义struct Name。在定义struct Person之前定义struct Name