我有以下类,当我尝试编译时,我得到一个错误,声明它不是一个类型。 我究竟做错了什么? Owner.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
Owner.cpp
#include <iostream>
#include <string>
#include "owner.h"
using namespace std;
Owner::Owner()
{
}
Email Owner::ownerEmails()
{
Email e;
return e;
}
email.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
答案 0 :(得分:1)
根据给定的信息进行猜测
Email
嵌套在命名空间或其他类/ struct 不对您对错误消息的解释做出任何假设......
答案 1 :(得分:1)
删除#include "email.h"
并在class Email
中声明class Owner
之前添加owner.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