explicit specialization 显式指定

时间:2024-06-08 19:07:32
//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 = ;
msg msg;
msg.title = "Attention";
msg.content = "Perimeter has been breached, evacuate to section 7."; Broadcast(simpleMsg);
Broadcast(msgNum);
Broadcast(msg); cin.get();
return ;
} 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;
}

explicit specialization 显式指定