template

 1 #include <iostream>
 2 using namespace std;
 3
 4 template <typename T1, typename T2>
 5 class complex
 6 {
 7 public:
 8     T1 real;
 9     T2 imag;
10     complex();
11     complex(T1 r, T2 i);
12     complex(const complex<T1, T2> &R);
13     complex &operator=(const complex<T1, T2> &R);
14 };
15
16 template <typename T1, typename T2> complex<T1, T2>::complex():real(0),imag(0)
17 {
18 }
19
20 template <typename T1, typename T2> complex<T1, T2>::complex(T1 r, T2 i)
21 {
22     real = r;
23     imag = i;
24 }
25
26 template <typename T1, typename T2> complex<T1, T2>::complex(const complex<T1, T2> &R)
27 {
28     real = R.real;
29     imag = R.imag;
30 }
31
32 template <typename T1, typename T2> complex<T1, T2> &complex<T1, T2>::operator=(const complex<T1, T2> &R)
33 {
34     real = R.real;
35     imag = R.imag;
36     return *this;
37 }
38
39 template <typename T1, typename T2> ostream &operator<<(ostream &out, const complex<T1, T2> &R)
40 {
41     out<<"real:"<<R.real<<"   imag:"<<R.imag;
42     return out;
43 }
44
45 template <typename T1, typename T2> complex<T1, T2> operator+(const complex<T1, T2> &L, const complex<T1, T2> &R)
46 {
47     complex<T1, T2> sum;
48     sum.real = L.real + R.real;
49     sum.imag = L.imag + R.imag;
50     return sum;
51 }
52
53 int main()
54 {
55     complex<int, int> a(2,3), b(3, 2);
56     complex<int, int> c = a + b;
57     cout<<c<<endl;
58 }
时间: 2024-12-19 10:13:28

template的相关文章

NET Core项目定义Item Template

NET Core项目定义Item Template 作为这个星球上最强大的IDE,Visual Studio不仅仅提供了很多原生的特性,更重要的是它是一个可定制的IDE,比如自定义Project Template和Item Template就是一个非常有用的扩展点.这里我们主要关注Item Template,它时我们可以在"Add new Item"对话框中添加我们自定义的Item(如下图所示).如果不了解Item Template,Scott Gu的文章. 我们之前自定义了一些Ite

手把手教你创建Azure ARM Template

Azure的ARM模式在中国已经落地了.在ARM模式中,通过ARM的Template批量的创建各种资源是与ASM模式的最大的区别之一.目前Azure ARM的Template数量已经越来越多,更多的客户会选择采用Template的模式进行资源的部署: 在前面的文章中已经介绍了如何通过已有的Template修改成你所需要的模板,请参考: http://www.cnblogs.com/hengwei/p/5634380.html 本文将一步一步的创建一个最简单的存储账户的ARM Template,并

Backbone 模板 underscore template默认的转义符&lt;%= %&gt; 与jsp的冲

先定义转义符,因为默认的转义符<%= %> 与jsp的冲突(如果js模板写在jsp页面中)       _.templateSettings = { interpolate : /\{\{(.+?)\}\}/g }; 下面就可以这样写 <script type="text/template" id="detailedBar-template"> <div class='title'> <span class='label'&

ansible的playbook配置及template模板的使用

前言: 学习下ansible的playbooks的状态配置管理,说来puppet saltstack都有类似的叫法,只是ansible的叫法更犀利,我当时一看playbook还以为是花花公子的playboy.要使用ansible就要深入学习playbook配置及模板. 注:到底是playbook还是playbooks.... 先把官网的简单几个语法给说明下. #这个是你选择的主机 - hosts: webservers #这个是变量   vars:     http_port: 80     m

Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file &quot;/WEB-INF/ftl/common/errormessage.ftl&quot;

初次接触spring mvc,想做一个小的练习项目,结果在ftl文件中引用其它的共通ftl文件时出错. 目录结构如图所示,想在login.ftl中引用common下的errormessage.ftl <#include '/WEB-INF/ftl/common/errormessage.ftl' /> 结果画面报错: FreeMarker template error: Error reading included file "/WEB-INF/ftl/common/errormes

Spring Boot使用thymeleaf模板时报异常:template might not exist or might not be accessible by any of the configured Template Resolvers

错误如下: template might not exist or might not be accessible by any of the configured Template Resolvers 解决方法: 1.确定模板是否在默认templates文件夹里面,并且路径要和返回的View名字一致. 2.new ModelAndView("/log/loglist");这样写是不对的,应该把开头的斜杠去掉,改成:new ModelAndView("log/loglist&

HDOJ 1217 Floyed Template

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cstring> 5 #include<map> 6 using namespace std; 7 8 map<string,int>name; 9 const int INF = 1000000; 10 const int MAXSIZE = 1005; 11 const int

微信小程序 模板template的使用

一.文件目录结构如下: 二.在house页面使用这些模板: 三.在house页面引入样式 四.定义模板文件 五.总结: 1.在模板文件中必须以name="模板名称" 如: <template name="HeaderNavTemplate">......</template> 包裹: 2.在引入模板页面.wxml页面中 <import src="../template/tpl-headerNav/tpl-headerNav.w

设计模式的征途—17.模板方法(Template Method)模式

在现实生活中,很多事情都需要经过几个步骤才能完成,例如请客吃饭,无论吃什么,一般都包含:点单.吃东西.买单等几个步骤,通常情况下这几个步骤的次序是:点单=>吃东西=>买单.在这3个步骤中,点单和买单大同小异,最大的区别在于第2步-吃什么?吃面条和吃满汉全席可大不相同. 在软件开发中,有时候也会遇到类似的情况,某个方法的实现需要多个步骤(类似于“请客”),其中有些步骤是固定的,而有些步骤则存在可变性.为了提高代码复用性和系统灵活性,可以使用一种称之为模板方法模式的设计模式来对这类情况进行设计.

C++中template的简单用法

模板(Template)指C++程序设计设计语言中采用类型作为参数的程序设计,支持通用程序设计.C++ 的标准库提供许多有用的函数大多结合了模板的观念,如STL以及IO Stream.使用模板可以使用户为类或者函数声明一种一般模式,使得类中的某些数据成员或者成员函数的参数.返回值取得任意类型. 一.函数模板 在c++入门中,很多人会接触swap(int&, int&)这样的函数类似代码如下: 1 void swap(int&a , int& b) { 2 int temp