#include <string>
#include <iostream>
#ifndef NAME_H
#define NAME_H
class Name
{
private:
std::string first_,last_ ;
public:
explicit Name(const std::string & first = "john", const std::string & last = "doc"):first_(first),last_(last)
{
if(!isvalidlast(last_) || isvalidfirst(first_))
throw "Name :: Name(const string &,const string &):invalid Name";
}
static bool isvalidlast(const std::string & last){}
static bool isvalidfirst(const std::string & first){}
std::string getfirst() const
{
return first_;
}
bool setfirst (const std::string & first)
{
if(!isvalidfirst(first)) return false;
first_=first;
return true;
}
friend std::istream & operator >> (std::istream &,Name &);
friend std::ostream & operator <<(std::ostream &,Name &);
}; //end of class defn
inline std::ostream & operator << (std::ostream & os,const Name & n)
{
return os << n.first_ << ' ' << n.last_;
}
inline std::istream & operator >> (std::istream & is,Name & n)
{
return is >> n.first_ >> n.last_;
}
#endif
.cpp
#include <set>
#include <iostream>
#include "Name.h"
//using namespace std;
int main()
{ Name n;
std::set<Name> s;
while(cin >> n)
s.insert(n);
}