Reputation: 1796
I have the following class and when I try to compile I get an error stating that it is not a type. What am I doing wrong? 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
Upvotes: 1
Views: 130
Reputation: 122401
Remove #include "email.h"
and add a forward declaration of class Email
before you declare class Owner
in 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
Upvotes: 1
Reputation: 787
Guessing based on the given information
Email
is nested in a namespace or other class/structMaking no assumptions about your interpretation of the error messages ...
Upvotes: 1