C ++'电子邮件'不能命名类型

时间:2013-06-05 16:30:02

标签: c++ class qt-creator

我有以下类,当我尝试编译时,我得到一个错误,声明它不是一个类型。 我究竟做错了什么? 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

2 个答案:

答案 0 :(得分:1)

根据给定的信息进行猜测

  • Email嵌套在命名空间或其他类/ struct
  • email.h拼错了,你无意中忽略了找不到email.h的错误(也许是Email.h
  • 包含警卫是错误的(可能是email.h中的OWNER_H)

不对您对错误消息的解释做出任何假设......

  • 电子邮件是模板类
  • email.h中某处有一个近距离缺席
  • email.h或phone.h中没有定义任何电子邮件类型

答案 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