1

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
Talon06
  • 1,756
  • 3
  • 27
  • 51

2 Answers2

1

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
Steven Maitlall
  • 777
  • 3
  • 5
1

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
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • When I forward the class it gives this error: return type 'class Email' is incomplete I understand that is because the compiler does not yet know what is in the class. Is there a way around this. I found the following, but have not been able to put it to use. http://stackoverflow.com/questions/553682/when-to-use-forward-declaration – Talon06 Jun 05 '13 at 17:47
  • 1
    @Talon06 Yes, pass it back via a reference: `void ownerEmails(Email &email);`. – trojanfoe Jun 05 '13 at 18:22