#include
using namespace std;
class Sample
{
private:
int x;
public:
Sample () { }
Sample(int a){x=a;}
void disp(){cout<<"x="<<x<<endl;}
friend Sample operator+( Sample &s1, Sampl...
分类:
其他好文 时间:
2015-04-23 13:34:08
阅读次数:
135
问题:
(1)请用类的成员函数,定义复数类重载运算符+、-、*、/,使之能用于复数的加减乘除
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r; imag=i;}
Complex operator+(const Complex &c2);
Co...
分类:
其他好文 时间:
2015-04-23 13:28:53
阅读次数:
137
考察优先队列,不过要注意优先队列的优先排序是不稳定排序,解决方法和自定义排序一样,再添加一个参数即可
#include
#include
using namespace std;
string cmd;
struct stu
{
string name;
int p,lv,num;
friend bool operator<(stu x,stu y)
{
if(x.lv==y.lv)...
#include
#define DefaultSize 10
using namespace std;
template
class Grail
{
public:
Grail()
{
data = new T[DefaultSize];
for(int i=0;i<10;i++)
{
data[i]=i;
}
}
const T& operator[](...
分类:
编程语言 时间:
2015-04-22 11:43:48
阅读次数:
164
题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数。
class CMyString
{
public:
CMyString(char* pData = NULL);
CMyString(const CMyString& str);
~CMyString(void);
CMyString& operator = (const CMyString...
分类:
其他好文 时间:
2015-04-22 00:43:45
阅读次数:
198
考察优先队列,以及对队列的一系列操作
#include
#include
#define maxn 10000+10
using namespace std;
struct stu
{
string name;
int rp;
friend bool operator<(stu x,stu y)
{
if(x.rp==y.rp) return x.name<y.name;
ret...
分类:
其他好文 时间:
2015-04-21 16:09:20
阅读次数:
154
《effective c++》的确是一本神书,阅读起来的感觉可以用酣畅淋漓来形容,似乎很多以前没有在意的小细节都变得豁然开朗了起来,在条款10中,scott建议我们重载操作符’=’时,返回一个*this的引用。
赋值,我们往往可以写作连锁形式:
int x,y,z;
x = y = z = 10;赋值采用了右结合律,所以以上连锁赋值被解析为:x = (y = (z = 10));首先15...
分类:
编程语言 时间:
2015-04-21 01:52:38
阅读次数:
112
C++仿函数应用实例#include
#include
#include using namespace std;template
struct GT
{
GT (const T& a) : m_a(a) {}
bool operator()(const T& left)
{
retu...
分类:
编程语言 时间:
2015-04-19 22:51:14
阅读次数:
163
tbLog log = new tbLog(); log.Operator_name = "test"; //1会员,2服务中心,3管理员 log.Operator_Type = "管理员"; ...
分类:
数据库 时间:
2015-04-19 00:55:47
阅读次数:
213
Sightseeing
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 718 Accepted Submission(s): 293
Problem Description
Tour operator Your P...
分类:
其他好文 时间:
2015-04-18 23:48:52
阅读次数:
164