Ok I believe my problem is that when I create my Graph object I am not passing it the correct reference to the vector.
That is how I'm currently calling it which calls the default destructor.Code:static Graph actorGraph;
But I need to pass it a reference of the vector stored in my ActorDB class. So I created a function in my ActorDB.cpp class to return the reference to the vector:
But now I don't know how to access this funtion from my Movie class, which is where I create my graph. I tried calling it with:Code:vector<Actor> * ActorDB::pointer()
{
return &data;
}
But that's just an error. Anyone know how I can call this function from my Movie class?Code:static Graph actorGraph(adb->pointer());
Here is my Graph.h file....
This is the Movie class.....Code:class Graph
{
public:
Graph( ) { }
Graph( std::vector<Actor> * d ) : data(d) { } ----->Constructor I want
~Graph( );
void addEdge( const ActorDB::tag & sourceName, const ActorDB::tag & destName, double cost );
void printPath( const ActorDB::tag & destName ) const;
void unweighted( const ActorDB::tag & startName );
//void dijkstra( const std::string & startName );
void addVertex (const ActorDB::tag & startName);
private:
Vertex * getVertex( const ActorDB::tag & vertexName );
void printPath( const Vertex & dest ) const;
void clearAll( );
typedef map<int ,Vertex *,less<ActorDB::tag> > vmap;
// Copy semantics are disabled; these make no sense.
Graph( const Graph & rhs ) { }
const Graph & operator= ( const Graph & rhs )
{ return *this; }
std::vector<Actor> * data;
vmap vertexMap;
};
Code:class Movie
{
public:
Movie();
/**
* Build a new movie.
*
* @param t The title of the movie
* @param y The year string for this movie
* @param a A pointer to the ActorDB object. The movie stores actor tags
* taken from this object.
*
*/
Movie(const std::string& t, const std::string& y, ActorDB* a = 0);
/// return the title of the movie
std::string title() const;
/// returns the year in which the movie was made.
std::string year() const;
/**
* Add an actor to the movie's cast list. Takes a tag from the actor database
* as input. Note that it's marked "const" -- the cast list does not participate
* in the ordering of Movies; two Movies are logically equal if their titles and years
* are equal. Thus, the cast list is a mutable member of the Movie.
*
* @param a a tag referring to an actor to add to the list. To dereference such a tag,
* we have to pass it back to the ActorDB object it came from.
*/
void add_actor(ActorDB::tag a) const;
/**
* Returns a vector of Actors, the cast of this movie.
*
* @return a vector of copies of the Actors with roles in this movie.
*/
std::vector<Actor> cast() const;
void actorConnections(ActorDB::tag a) const;
void printPath(const ActorDB::tag & name1, const ActorDB::tag & name2);
private:
/// A pointer to the ActorDB that stores the actors with roles in this movie.
/// Used to resolve the ActorDB::tag objects that we store.
ActorDB* adb;
/// The title of this movie.
std::string the_title;
/// The year in which this movie was released.
std::string the_year;
/// A vector of ActorDB::tag objects, referring to the Actor objects
/// stored in *adb that represent our cast.
mutable std::vector<ActorDB::tag> the_cast;
///The private graph for the Kevin Bacon Problem
static Graph actorGraph(adb->pointer());
};
