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;
    }

  • 相关阅读:
    Functional Programming Contest
    CodeChef--SEPT14小结
    Weekly 10 小结
    CSS中的 REM PX EM
    phoenegap3.5 采坑
    PPT插件 用js制作PPT
    js 代码命名规范系列
    文档列表
    mockjax MOCK.js的拦截ajax请求
    css Tab选项卡
  • 原文地址:https://www.cnblogs.com/heben/p/9308137.html
Copyright © 2011-2022 走看看