Thread: Why am I getting this error?

  1. #16
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    Ok so I made actorGraph static. Now I have an error in my actorConnections function:

    "undefined reference to Movie::actorGraph"

    I'm sure this has something to deal with it being static, so is there anyway to fix that?

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Yeah. You have to define the object somewhere (there is only one). This is generally done at the top of the cpp file.
    Code:
    Graph Movie::actorGraph;

  3. #18
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    Ok so here's my problem now....

    Code:
    #include "App.h"
    
    #include "Movie.h"
    #include "Actor.h"
    #include "ActorDB.h"
    #include "MovieDB.h"
    
    
    #include <string>
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    App::App()
    {
    }
    
    App::~App()
    {
    }
    
    void App::read_file(const std::string& fname)
    {
    	ifstream infile(fname.c_str());
    	if (!infile)
    		return;
    	
    	string actor_name;
    	while (getline(infile, actor_name, '\t')) {
    		//cout << "Actor: " << actor_name << endl;
    		
    		Actor current_actor(actor_name);
    		ActorDB::tag current_ref = adb.add_actor(current_actor);	
    		input_roles(current_ref, infile);
    	}
    }
    	
    void App::get_path() const
    {
    	while (true) {
    		Movie m;
    		cout << "Enter an actor's or actresse's name (q to quit): ";
    		string name;
    		getline(cin, name);
    		
    		if (name == "q")
    			break;
    			
    		cout << "\nEnter another actor or actress's name (q to quit): ";
    		string name2;
    		getline(cin, name2);
    		
    		if (name2 == "q")
    			break;
    		
    		m.printPath(name, name2);
    		
    		
    		
    	}
    }
    	
    void App::kevin_bacon() const
    {
    	
    }
    
    void trim(string& s) 
    {
    	int pos = 0;
    	while (s[pos] == '\t' || s[pos] == ' ')
    		++pos;
    	int pos2 = s.size()-1;
    	while (s[pos2] == '\t' || s[pos2] == ' ')
    		--pos2;
    	s = s.substr(pos, pos2-pos+1);
    }
    
    string find_year(string& mtxt) 
    {
    	int pos1 = mtxt.size();
    	do {
    		pos1 = mtxt.rfind('(', pos1-1);
    	} while (mtxt[pos1+1] != '1' && mtxt[pos1+1] != '2' && mtxt[pos1+1] != '?');
    
    	int pos2 = mtxt.find(')', pos1+1);
    	string year = mtxt.substr(pos1+1, pos2-pos1-1);
    	mtxt = mtxt.substr(0, pos1);
    	trim(mtxt);
    	return year;		
    }
    
    void App::input_roles(ActorDB::tag a, std::istream& in) {
    	while (true) {
    		string movie_txt;
    		if (!getline(in, movie_txt))
    			break;
    		if (movie_txt == "")
    			break;
    			
    		trim(movie_txt);
    		if (movie_txt[0] == '"')
    			continue;
    		
    		// we have a real movie.  Find the year.
    		
    		//cout << "   Movie txt: " << movie_txt << endl;
    		
    		string year = find_year(movie_txt);
    		//cout << "       Movie name: " << movie_txt << endl
    		//	 << "       Movie year: " << year << endl;
    		
    		Movie m(movie_txt, year, &adb);
    		MovieDB::tag t = mdb.add_movie(m);
    		const Movie& movie = mdb.get_movie(t);
    		
    		movie.add_actor(a);
    		movie.actorConnections(a);
    		
    		
    	}
    }
    I don't believe my vertices are being created. I think my problem lies where I call the printPath function with object m, but I'm calling actorConnections at the bottom to create the vertices with a different object (movie). Or does this not matter? Or is it some other problem?
    Last edited by tallguy; 04-02-2007 at 07:14 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM