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@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Welson Sun
Sent: Thursday, February 10, 2005 4:42 PM
To: boost-users@lists.boost.org
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