Talon06
Talon06

Reputation: 1796

C++ 'Email' Does Not Name A Type

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

Answers (2)

trojanfoe
trojanfoe

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

Steven Maitlall
Steven Maitlall

Reputation: 787

Guessing based on the given information

  • Email is nested in a namespace or other class/struct
  • email.h is spelled wrong and you unintentionally overlooked the error that email.h could not be found (perhaps Email.h)
  • The include guards are wrong (possibly OWNER_H in email.h)

Making no assumptions about your interpretation of the error messages ...

  • Email is a template class
  • There's a close-bracket missing somewhere in email.h
  • There is no Email type defined anywhere in email.h or phone.h

Upvotes: 1

Related Questions