hi, i overloaded the operator << as a friend function in this class, and when i compile the program i get this error:-
\customerType.cpp(90): error C2065: 'vtl' : undeclared identifier
as a friend function doesnt it have access to all private/protected members. Here is the code......what am i doing wrong?
customerType.h
Code:
#ifndef H_CUSTOMERTYPE
#define H_CUSTOMERTYPE
#include<iostream>
#include<string>
#include<list>
using namespace std;
class customerType
{
friend ostream& operator<<(ostream&, const customerType&);
protected:
string name;
int numCheckedOut;
list<string> vtl;
public:
bool operator < (const customerType& )const;//defined
bool operator == (const customerType& )const;//defined
void printCustomerName()const;//defined
void addTitle(string);
void removeTitle(string);
bool matchName(string);
void printCustomerTitles();
void setName(string);
void setNumCheckedOut(int);
customerType(string);
customerType();
void removeAllTitles();
string getName()const;
int numberChecked()const;
};
#endif
customerType.cpp
Code:
#include "customerType.h"
#include<list>
#include<iostream>
using namespace std;
bool customerType::operator < (const customerType& other)const
{
return (name < other.name);
}
bool customerType::operator == (const customerType& other)const
{
return (name == other.name);
}
void customerType::printCustomerName()const
{
cout<<"Customer Name: "<<name<<endl;
}
void customerType::addTitle(string mName)
{
vtl.push_back(mName);
numCheckedOut++;
}
void customerType::removeTitle(string mName)
{
vtl.remove(mName);
numCheckedOut--;
}
bool customerType::matchName(string Cname)
{
return( name == Cname );
}
void customerType::printCustomerTitles()
{
list<string>::const_iterator video;
for(video=vtl.begin();video!=vtl.end();video++)cout<<"Movie Name: " << *video<<endl;
}
void customerType::setName(string Cname)
{
name=Cname;
}
void customerType::setNumCheckedOut(int num)
{
numCheckedOut=num;
}
customerType::customerType(string cName)
{
name=cName;
numCheckedOut=0;
}
customerType::customerType()
{
name="";
numCheckedOut=0;
}
void customerType::removeAllTitles()
{
for(int i=0;i<numCheckedOut;i++)vtl.pop_back();
numCheckedOut=0;
}
string customerType::getName()const
{
return name;
}
int customerType::numberChecked()const
{
return numCheckedOut;
}
ostream& operator<<(ostream& os, const customerType& customer)
{
list<string>::const_iterator location;
os<<customer.name;
os<<customer.numCheckedOut;
for(location= vtl.begin();location!=vtl.end();location++)
{
os<<*location<<endl;
}
return os;
}