我怎么可以使用模板类型定义,是标签:APIWinHTTP一类,从类外(例如通过另一个类),就提振::图 [英] How can I use templated typedefs, that are _in_ a class, from outside the class (e.g. by another class), in relation to boost::graph

查看:122
本文介绍了我怎么可以使用模板类型定义,是标签:APIWinHTTP一类,从类外(例如通过另一个类),就提振::图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了如何创建在<一个使用boost ::图形模板图形的非常有用的答案href=\"http://stackoverflow.com/questions/671714/modifying-vertex-properties-in-a-boostgraph/950173#950173\">http://stackoverflow.com/questions/671714/modifying-vertex-properties-in-a-boostgraph/950173#950173

对于我来说,这是非常方便的,只要我做的所有在图形类本身的图形工作。

For me, this is very convenient as long as I do all the work on the graph in the Graph-class itself.

然而,可能有必要从外部访问的信息,例如人们可能想实现一个打印机类,需要一个图形对象,并打印出所有存储的信息。

However, it might be necessary to access information from outside, e.g. one might want to implement a Printer-class that takes a Graph-object and prints out all the stored information.

在这种情况下,它可能是方便的访问所有的顶点(例如,通过一个顶点迭代)。不幸的是,这是行不通的,因为所有的类型定义是在图形类完成,这一信息从外部是无法访问的,所以打印机类不会知道什么是顶点迭代器等的。

In that case, it could be handy to access all the vertices (e.g. by a vertex iterator). Unfortunately, this won't work, as all the typedef is done in the Graph-class and this information is not accessible from outside, so the Printer-class won't know what a vertex-iterator etc. is.

我怎么能解决这个问题,仍然保持模板化方面?

How could I address this issue and still keep the templated aspect?

感谢。

推荐答案

但类型定义是公开的,所以你可以从外部访问它们:

But the typedefs are public, so you can access them from outside:

template<typename T>
class A
{
public:
    typedef T type;
    typedef unsigned data;
};

现在,这是以下内容:

A<int>::type // int
A<int>::data // unsigned

要小心,如果未指定T被

Be careful, if T is not specified

template<typename T>
void func( A<T>& a )
{
    typename A<T>::type // T
    typename A<T>::data // unsigned
}

这篇关于我怎么可以使用模板类型定义,是标签:APIWinHTTP一类,从类外(例如通过另一个类),就提振::图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆