C++ 'Email'不命名类型
C++ 'Email' Does Not Name A Type
我有以下类,当我试图编译时,我得到一个错误,指出它不是类型。我做错了什么?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
删除#include "email.h"
,在owner.h
声明class Owner
之前增加class Email
的前向声明:
#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
根据给定信息进行猜测
-
Email
嵌套在命名空间或其他类/结构 - email.h拼写错误,你无意中忽略了email.h无法找到的错误(也许email.h )
- 包含守卫错误(可能是email.h中的OWNER_H)
对错误信息的解释不做任何假设…
- Email是一个模板类
- email中缺少一个右括号。h
- 在Email .h或phone.h中没有定义Email类型
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- 构造函数正在调用一个使用当前类类型的函数
- 我应该使用什么来代替void作为变体中的替代类型之一
- C++ 'Email'不命名类型