Boost logo

Boost Users :

From: Welson Sun (welson_sun_at_[hidden])
Date: 2005-02-10 22:25:36


Well, I found out that this is not a problem related to inheritence nor
polymorphism, it is a problem with the BGL

1. Even if I make BasicOperator not inherit from Operator, the problem is
the same.
Here is the modified BasicOperator:

class BasicOperator /* : public Operator */{
public:
  BasicOperator() {};
  BasicOperator(OperatorType* type) : _type(type) {toString =
_type->getMnemonic();};
  BasicOperator(OperatorType* type, string cust) : _type(type), _cust(cust)
{toString = _type->getMnemonic() + "&" + _cust;};
  OperatorType* getOperatorType() { return _type; }
  string toString() { return toString; }
  string toString;
private:
  OperatorType* _type;
  string _cust;
};

And the vertex property writer is:
  void operator()(std::ostream& out, const Vertex& v) const {
    out << "[label=\""
        << "(" << g[v].toString() << ")"
        << "\"]";
  }

The error is:
main.cpp:52: error: passing `const BasicOperator' as `this' argument of `
   std::string BasicOperator::toString()' discards qualifiers

So it looks like that the problem is related to the "const" BasicOperator I
passed into std::string BasicOperator::toString(). How can I fix this? Which
means if the property of a vertex is a Class, how can I call its member
function in the vertex writer?

2. If I changes the vertex property writer as:
  void operator()(std::ostream& out, const Vertex& v) const {
    out << "[label=\""
        << "(" << g[v].toString << ")"
        << "\"]";
  }
Everything is OK. Which mean in the vertex property writer, I can access the
data member without any problem, but I cannot access the member function.
 

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Welson Sun
Sent: Thursday, February 10, 2005 4:42 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] Another C++ inheritence/polymorphism problem

Hi, here is another problem I met:

$ g++ main.cpp
main.cpp: In member function `void
   schedule_vertex_writer<Graph>::operator()(std::ostream&, const Vertex&)
   const [with Vertex = unsigned int, Graph =
   boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
   BasicOperator, boost::no_property, boost::no_property, boost::listS>]':
/usr/local/include/boost/graph/graphviz.hpp:264: instantiated from `void
boost
::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter,
EdgeProper tiesWriter, GraphPropertiesWriter) [with Graph =
boost::adjacency_list<boost::ve cS, boost::vecS, boost::bidirectionalS,
BasicOperator, boost::no_property, boost ::no_property, boost::listS>,
VertexPropertiesWriter = schedule_vertex_writer<bo
ost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
BasicOperat or, boost::no_property, boost::no_property, boost::listS> >,
EdgePropertiesWrite r = boost::default_writer, GraphPropertiesWriter =
boost::default_writer]'
/usr/local/include/boost/graph/graphviz.hpp:292: instantiated from `void
boost
::write_graphviz(std::ostream&, const Graph&, VertexWriter) [with Graph =
Graph, VertexWriter =
schedule_vertex_writer<boost::adjacency_list<boost::vecS,
boost:
:vecS, boost::bidirectionalS, BasicOperator, boost::no_property,
boost::no_prope rty, boost::listS> >]'
main.cpp:93: instantiated from here
main.cpp:52: error: passing `const BasicOperator' as `this' argument of `
   virtual OperatorType* BasicOperator::getOperatorType()' discards
qualifiers

The source code is in the attachment.

Thanks!


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net