Hello,
I have a base class Paths, and a derived class LanguagePaths, which inherits Paths. There are various members of Paths, namely two doubles and a std::list <int>, which I'd like to copy from a Paths object into a LanguagePaths object.
In order to do so, I've overloaded the operator= in LanguagePaths, as follows :
Code:// LANGUAGE PATHS CLASS #ifndef _LANGUAGEPATHS_H #define _LANGUAGEPATHS_H //#include <list> #include <set> #include "paths.h" #include "shortcuts.h" class LanguagePaths : public Paths // INHERITS PATHS { public: // Constructor LanguagePaths(); // Accessors bool banned(uint); // Check if a production is banned void insert(uint); // Insert a ban listitr marker(); // Marker position listitr setmarker(listitr); // Set the position of the marker // Overloaded operator LanguagePaths operator= (const Paths &); private: // Ban list set <uint> ban; // Marker position listitr markerpos; }; #endifCode:// SNIPPET OF LANGUAGEPATHS.CPP // Overloading the equals operator LanguagePaths LanguagePaths::operator=(const Paths & original) { // Set length and coefficients equal length = original.length; coefficient = original.coefficient; // Set path description to be the same path = original.path; }Code:// PATHS CLASS #ifndef _PATHS_H #define _PATHS_H #include <list> #include "edge.h" #include "vertex.h" #include "graph.h" #include "shortcuts.h" using namespace std; class Paths { public: // Constructor Paths(); // Accessors uint back(); // Returns the ID of the vertex at the end of the path uint front(); // Returns the ID of the vertex at the front of the path int size(); // Returns the size of the path, in number of nodes double getLength(Graph &); // Returns the length of the path in spatial units double getCoefficient(Graph &); // Returns the trip coefficient of the path // Iterators listitr begin(); // Returns an iterator to the beginning of the list listitr end(); // Returns an iterator to the end of the list // Other methods void push_back(uint); // Add a vertex to the end of the path bool contains(uint); // Check if the path contains a certain vertex void clear(); // Clear the path list completely void incLength(double); // Increase the length of the path void incCoefficient(double); // Increase the trip coefficient protected: double length; // Path length double coefficient; // Path coefficient list <uint> path; // Path description }; #endif
I'm struggling to use my equals operator. I have a list <Paths> which contains path objects, and want to create a std::priority_queue <LanguagePaths>, like so :
Code:// Create a priority queue using specified comparison function priority_queue < LanguagePaths, vector <LanguagePaths>, PathCompare > pq(comparefunction); // Create a temp LanguagePaths object LanguagePaths temp; for(list<Paths>::iterator i = finallist.begin(); i != finallist.end(); i++) { temp = *i; pq.push(temp); }
I get these errors :
I get the same error for Paths::coefficient and Paths::path.Code:paths.h: In member function 'LanguagePaths LanguagePaths::operator=(const Paths&)': paths.h:45: error: 'double Paths::length' is protected
I was under the impression that protected members of a base class could be accessed by a derived class. I'm not quite sure what I should be doing.
Any help would be greatly appreciated. Thanks very much !
Quentin



LinkBack URL
About LinkBacks


