作者supercygnus (......)
看板Programming
标题[问题] 两题C++的问题
时间Mon Apr 4 23:44:31 2011
第一题:试用C++里function template的方式,
写出一个swap function,作任何两个相同型态变数的交换功能。
以下是我的程式码
#include <iostream>
#include <cstdlib>
using namespace std;
template<class T>
T swap(T &a,T &b){
int temp;
temp=a;
a=b;
b=temp;
}
int main(void){
cout<<"swap(5,8)="<<swap(5,8)<<endl;
system("pause");
return 0;
}
我有想到用call by reference的方式,可是要怎麽写到样版呢~?
目前程式码不能跑
第二题:利用C语言的语法,定义下列资料型态:
Structures BitCard包含三个unsigned bit栏位(fields),
换言之,face, suit, color的长度分别是4, 2及1 bits。
长度分别是4, 2及1 bits。怎麽有这麽短的资料型态,到底是???
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.98.95
※ 编辑: supercygnus 来自: 114.44.98.95 (04/04 23:45)