我有以下类,当我尝试编译时出现错误,指出它不是一个类型。 我究竟做错了什么? 所有者.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/