您当前的位置: 首页 >  c++

Jave.Lin

暂无认证

  • 2浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ 模板成员的非指针类型的成员初始化

Jave.Lin 发布时间:2020-07-10 18:11:48 ,浏览量:2

在这里插入图片描述

留意上面的图片中 底部的蓝底白字 的警告内容。

因为类型是不确定的,所以初始化也比较麻烦的。

不过我们也可以使用 T* 指针类型的来初始化为 NULL / nullptr

在这里插入图片描述

下面测试代码:

// jave.lin - testing for template_type_member_init
#include
#include

template
class Test {
public:
    // T test_default = static_cast(0);
    T test_default = static_cast(NULL);
};

template
class TestPointer {
public:
    T* test_default = NULL;
};

class Custom_CLZ { };
class Custom_STC { };

class CAN_NOT_OUTPUT_CLZ { };

#define P(content)\
    std::cout             
关注
打赏
1664331872
查看更多评论
0.0383s