c++ template trait 用法

时间:2021-05-19 23:35:51   收藏:0   阅读:16

tempalte trait 用法

Trait 用法的好处

Trait 用法在结构体中

    template <typename T> 
    class AA 
    {
        T Get(); 
        T Set(); 
    };

复杂信号的实现逻辑


template <typename a , bool b = true ,typename ItempType = typename a::ItemType> struct  Owner; 

template <typename a , typename ItempType > 
struct  Owner<a,true,ItempType>
{
	Owner(){printf("owner1\n");}
}; 

template <typename a ,typename ItempType> 
struct  Owner<a,false,ItempType>
{
	Owner(){printf("owner2\n");}
}; 

struct helloTraits 
{
	typedef int ItemType ; 
	ItemType aaa ; 
};

原文:https://www.cnblogs.com/ljymoonlight/p/14787688.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!