samedi 28 février 2015

Boost Graphs. Equivalent technique to Inheritance


I am pretty new to Boost Graphs and perhaps there is a solution to my problem.


I have a function that performs certain computation on a graph. It expects graphs with a particular properties, e.g. it expects that all edges will have a numerical weight value and all vertices will have a numerical field (lets call it a color, it will be preset to some meaningful value prior to call to my function).


Imagine that I have a set of different graph types, all of them have numeric weight property on a link and all their vertices have a numeric color, however they also have other properties for vertices and edges. My question is how can I use my function for all of these graph types?



  1. Naturally to me it seems like an inheritance, if boost graphs would be classes then my function could operate on a base classes, and I could pass in pointer to a child classes etc.

  2. Initially I've been trying to declare my function to take in a template graph argument, but soon I realized that it doesn't work (or I couldn't figure out how to do it properly).


Thanks!




Aucun commentaire:

Enregistrer un commentaire