C++ 'Email' 没有命名类型

标签 c++ class qt-creator

我有以下类,当我尝试编译时出现错误,指出它不是一个类型。 我究竟做错了什么? 所有者.h

#ifndef OWNER_H
#define OWNER_H
#include <iostream>
#include <string>
#include "email.h"
#include "phone.h"

using namespace std;

class Owner 
{
public:
Owner();
Email ownerEmails();
private:
int intID;
string strFirstName;
string strLastName;
string strAddress1;
string strAddress2;
string strCity;
string strState;
int intZip;
};

#endif // OWNER_H

所有者.cpp

#include <iostream>
#include <string>
#include "owner.h"

using namespace std;

Owner::Owner()
{
}

Email Owner::ownerEmails()
{
Email e;
return e;
}

电子邮件.h

#ifndef EMAIL_H
#define EMAIL_H
#include "owner.h"
#include <iostream>
#include <string>

using namespace std;

class Email
{
public:
Email();
Email(int intID);
void setOwner(Owner o);
void setEmail(string email);
void setType(string type);
Owner getOwnerID();
private:
string getEmail();
string getType();
int intID;
Owner owner;
string strEmail;
string strType;
};

#endif // EMAIL_H

最佳答案

删除 #include "email.h" 并在 owner 中声明 class Owner 之前添加 class Email 的前向声明.h:

#ifndef OWNER_H
#define OWNER_H
#include <iostream>
#include <string>
//#include "email.h"
#include "phone.h"

using namespace std;

// forward
class Email;

class Owner 
{
    ...
};

#endif // OWNER_H

关于C++ 'Email' 没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16945199/

相关文章:

c++ - 模板参数名称隐藏

c++ - 在 Bison : Where to define the class? 中作为返回类型分类

c++ - Qt 没有这样的方法插槽

c++ - QT Creator中如何使用FMOD工具?

c++ - 链接静态库和动态库时违反 ODR

c++ - 更好的说法 x == Foo::A || x == Foo::B || x == Foo::C || ...?

java - 打印具有 3D 数组字段的类

python - PyCharm:内置阴影名称 'self' ,错误还是功能?

Python 类作为对象

qt - 在 Qt Creator 中运行 Debug模式