栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++

graph_tool中的::type

参考网址:C++ template typedef
graph_tool中使用结构体::type的含义就是用这个结构体指定一个type类型为type代替原来的复杂的类型。

    struct apply
    {
        typedef typename boost::graph_traits::vertex_iterator type;
    };

    template 
    static std::pair::type,
                     typename apply::type>
    range(Graph& g)
    {
        return edges(g);
    }

结构体有一些参数是固定的,这样可以少写几个参数,比如说下面的例子,最后用Vector<3>::type代替Matrix1。这样做还有一个好处是,Vector和Matrix1可以分开定义。如下面例子中Vector是一个模板结构体,而Matrix1是一个类。

example

使用typedef定义一个Vector,相当于一个(N,1)大小的矩阵。

typedef Matrix Vector;

上面这个编译不通过。
要使用参考网址里面的这个:
首先定义一个Matrix1类。

template 
using Vector = Matrix;

然后再定义一个结构体模板Vector:

template 
struct Vector
{
    typedef Matrix type;
};

完整代码:

#include
//#include

//typedef Matrix Vector;
template
class Matrix1 {
    int a[N][M]={0};
    // 构造函数可以不要,编译能够通过。
    public:
    // 注意声明函数为公共函数!!!否则不可见。
    void init(int A[N][M]){
        for(int i=0;i
struct Vector
{
    typedef Matrix1 type;
};


int main(){
    // 
    Vector<3>::type a;
    int A[3][1]={{1},{2},{3}};
    int B[3][1]={1,2,3};
    a.init(B);
    for(int i=0;i<3;i++){
        std::cout<< 2-i <<" "<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/587429.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号