class NodeTypeA {};
class NodeTypeB : public NodeTypeA {
NodeTypeB () : NodeTypeA() {...;}
NodeTypeB (const NodeTypeA & obj) {...;}
NodeTypeB & operator=(const NodeTypeA & obj) { ...return *this;}
};
But It do not want to compile.
The compiler error is : error: no match for ‘operator=’ in ‘vec_second = vec_first’
I get some allocator message.candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = NodeTypeB, _Alloc = std::allocator<NodeTypeB>]
Do you have a solution that could handle different type via inheritance ?
That could perform something like :
vector<Animals*> = vector< Biped * >;
Hmm. Well this doesn't make sense to me. The thread is rather confusing since I am not sure why you would want to make such assignments. You have to pervert the assignment operator to do the assignments in the early examples. However now you are dealing with pointers. If this has something to do with polymorphisism where the vectors contain objects of pointer types where the class inherits from a common base then you need to use a cloning operation. Instead of doing assignment you could use the std::for_each algorithm.
The std::foreach_algorithm is the only one that I know of where the functor can be passed by value and accumulate data. You could use for_each to clone each object from the original and insert it into a new container that is a member of the functor. for_each returns the functor by value which can then be assigned. The call would look something like this. Either that or you have to make your own for loop where you clone each object and insert the clones into the new array. It'd be nice to learn more about your program requirements so that the gurus can help you with whatever you are really having trouble with. I don't agree with the design of having an assignment operator that converts to different data types. That is not what it is for.
The fact is that I have created a graph with boost.
And the graph show me relation between the nodes stored in a vector.
I have encapsulated the graph and the vector in a class named genericGraph<T>.
When I used the graphivz file output the boost structure used the ostream operator defined for the node.
So I cannot change the make different version of the ostream operator (a classic, one, a html typed one, ....)
So I have think to change the class of the vector in order to change the ostream operator and so allow a export of new label values.
This is what I have done, but the problem is the vector copy.
I get the following class :
1 2 3 4 5 6 7
template <class T>
class genericGraph : public boost::adjacency_list<boost::vecS,boost::vecS,DirectedS>
{
...
private:
vector<T> vec_nodes
}
So when I create a genericGraph of AnimalA it cannot be copied to AnimalB.
1 2 3 4 5 6
genericGraph<AnimalA> arbreAnimalA;
...
// The following line do no work :
genericGraph<AnimalB> arbreAnimalB = arbreAnimalA;
// because the vector of AnimalA cannot be converted to AnimalB.