zoukankan      html  css  js  c++  java
  • explicit specialization 显式指定

    //explicit specialization 显式指定
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct msg
    {
        string title;
        string content;
    };
    
    //非模板函数
    void Broadcast(const string& msg);
    
    //模板函数
    template <typename T>
    void Broadcast(const T& msg);
    
    //explicit specialization 显式指定
    template<> void Broadcast<msg>(const msg& msg);    
    
    int main(void)
    {
        string simpleMsg = "You just receive one message";
        int msgNum = 73357;
        msg msg;
        msg.title = "Attention";
        msg.content = "Perimeter has been breached, evacuate to section 7.";
    
        Broadcast(simpleMsg);
        Broadcast(msgNum);
        Broadcast(msg);
        
        cin.get();
        return 0;
    }
    
    void Broadcast(const string& msg)
    {
        cout << "Notice: " << msg << endl;
    }
    
    template <typename T>
    void Broadcast(const T& msg)
    {
        cout << "No: " << msg << endl;
    }
    
    template<> void Broadcast<msg>(const msg& msg)
    {
        cout << endl;
        cout << "************************************" << endl;
        cout << "Title: " << msg.title << endl;
        cout << "Content: " << msg.content << endl;
        cout << "************************************" << endl;
    }

  • 相关阅读:
    共用体
    建立动态链表
    动态分配储存与链表
    结构指针变量作函数参数
    R语言实战 第7章
    R-6 线性回归模型流程
    R-5 相关分析-卡方分析
    R-4 方差分析
    R-3 t分布--t置信区间--t检验
    R-2
  • 原文地址:https://www.cnblogs.com/heben/p/9308137.html
Copyright © 2011-2022 走看看