CODE
#ifndef ADDRESS_BOOK_H
#define ADDRESS_BOOK_H
// address_book.h
// class Image and AddressBookEntry declarations
#include <iostream>
#include <string>
//#include <algorithm>
using namespace std;
#include <boost/smart_ptr.hpp>
using namespace boost;
#include "Person.h"
//! A dummy class for image data.
class Image
{
public:
Image(const string& image_data_filename):
_image_filename(image_data_filename)
{
// read image file from disk ...
};
string name() {return _image_filename;};
void name(string newname) { _image_filename = newname; }
private:
string _image_filename;
// data member to store image ...
};
// -------------------------------------------------------
class AddressBookEntry
{
public:
//constructor for AddressBookEntry
AddressBookEntry(const Person& person, const string& image_filename = "");
// copy constructor for the AddressBookEntry
AddressBookEntry(const AddressBookEntry& rhs)
//Assignment operator
AddressBookEntry& operator =(const AddressBookEntry& rhs)
void mySwap(AddressBookEntry & temp)
string getImageName() const;
void setImageName(string newname);
Person getPerson() const { return _person; }
private:
Person _person
scoped_ptr<Image> _image_ptr
};
#endif
//Attempt to implement copy constructor & assignmnent operator
AddressBook::AddressBookEntry(const AddressBookEntry& rhs):
// this is where trouble comes in !!!
_person(rhs.getPerson()),
_image_pt(rhs.getImageName());
{ }
AddressBook::operator=(const AddressBookEntry& rhs):
{
// create temp for rhs to ensure atomic operation
AddressBookEntry temp(rhs);
//swap temp with the object being assigned
mySwap(temp);
//return the object being assigned
return *this;
}
// here is my :angry: swap function using the swap from <algorithm >
void AddressBookEntry::mySwap(AddressBookEntry & temp)
{
// swap each data member for the two object
_person.swap(temp.getPerson());
//another trouble spot here !!
_image_ptr(temp.getImageName());
}
edit: added [code] tags, moved to C/C++ ~ jayman9