我在使用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

这是我的main.cpp:
#include "pch.h"
#include <iostream>
#include "Person.h"
using namespace std;
int main()
{
return 0;
}

当我编译该文件时,出现以下错误:
  • '名称':未知的覆盖说明符缺少类型说明符-int
    假定。
  • 注意:C++不支持default-int

  • 有人可以教我如何解决此问题吗?

    最佳答案

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

    09-10 03:26
    查看更多