2
クラスメンバー/関数でtypedefを実行できますか?以下の例では、boost bimap関数を使用して、ノードの最近隣の情報を格納しています。クラスメンバーのtypedef
typedef boost::bimap<float /*distance*/, int /*id*/> neighbor_list;
neighbor_list node_a;
//fill up neighbors of node_a
//get nearest neighbor of node_a
node_a.neighbor.left.begin()->second;
//get distance to the nearest neighbor of node_a
node_a.neighbor.left.begin()->first;
しかし、上記の行は乱雑で直感的ではないかもしれません。私が、私はコードの乱雑一部をカプセル化しますが、私はだった自分自身の関数を書くことができます知っている次
typedef boost::bimap<float /*distance*/, int /*id*/> neighbor_list;
typedef neighbor_list::left::begin()->first nearest_neighbor;
//nearest neighbor of node_a
node_a.nearest_neighbor;
のような何かができるように、クラスメンバーのtypedef
を行うことが可能である場合ので、私は思っていました私がクラスメンバーに別名を与えることができるかどうか疑問に思います。
「typedef」はタイプ(驚き)です。関数は型ではありません。 –
しかし、意図した動作を別の関数でラップすることができます。これにより 'nearest_neighbor(node_a)'と入力することができます。 –
こんにちは私はそれを認識しています。私はまだC++の深いところを掘り下げていないので、私が求めたことをする方法があるかどうか疑問に思っていた。 – kong