public 公共,加上这个修饰的属性和方法,可以在程序的任何其它地方访问 。private 私有,和public相反,加上这个修饰的属性和方法,只允许在本类中访问。protected 保护,位于public和private中间,加上这个修饰的属性和方法,只能在子类(extends)和同包下的程序访 ...
分类:
其他好文 时间:
2016-03-26 10:51:44
阅读次数:
194
当类里面有指针对象时,采用简单的赋值浅拷贝,使得两个指针指向同一块内存,则析构两次,存在内存奔溃的问题,因此浅拷贝中利用引用计数。//引用计数浅拷贝classString
{
public:
String(char*str="")
:_str(newchar[strlen(str)+1])
,_pRefCount(newint(1))
{}
String(constS..
分类:
编程语言 时间:
2016-03-26 09:01:22
阅读次数:
145
#define_CRT_SECURE_NO_WARNINGS
#include<iostream>
usingnamespacestd;
template<classT>
classAuto_ptr
{
public:
Auto_ptr(T*_x):x(_x)
{}
Auto_ptr(Auto_ptr<T>&s):x(s.x)
{
s.x=NULL;
}
Auto_ptr&operator=(Auto_ptr<T>&s)
{
x=s...
分类:
编程语言 时间:
2016-03-26 08:49:48
阅读次数:
263
#include<iostream>
usingnamespacestd;
classString
{
public:
String(char*str="")//不能strlen(NULL)
:_str(newchar[strlen(str)+1])
{
strcpy(_str,str);
}
String(constString&s)
:_str(NULL)
{
Stringtmp(s._str);
swap(_str,tmp._str);
}
//String&ope..
分类:
其他好文 时间:
2016-03-26 08:39:43
阅读次数:
140
classCGoods{public: voidRegidter(char*m,inta,floatp);private: charmName[NAME_LEN]; intamount; floatprice;};voidCGoods::Regidter(char*m,inta,floatp){ strcpy(mName,m); amount=a; price=p;}intmain(){ CGoodsgood1; good1.Regidter("huanggua",10,2.8); return0;}this..
分类:
编程语言 时间:
2016-03-26 08:24:44
阅读次数:
133
用含成员函数的类来实现输入和输出时间。程序:#include<iostream>usingnamespacestd;classTime{public: voidset_time(); voidshow_time();private: inthour; intminute; intsec;};intmain(){ Timet1; t1.set_time(); t1.show_time(); Timet2; t2.set_time(); t2.show_ti..
分类:
其他好文 时间:
2016-03-26 08:13:55
阅读次数:
336
实现原理:单例模式的实现类,由一个私有静态变量和一个返回该私有静态变量的Public静态方法组成。实现类的构造方法设置为私有方法,每次调用getInstance时,进行判断,如果是第一次调用,则创建一个新实例,并且该实例赋值给静态变量。如果不是第一次调用,则直接返回已赋值过..
分类:
其他好文 时间:
2016-03-26 08:12:30
阅读次数:
96
#include using namespace std;class A
{
private:
int x;public:
A():x(0) { x = 0; cout << "construct" << endl; }
A(const A &a) { x = a.x; cout << "construct copy" << endl; }
~A(...
分类:
编程语言 时间:
2016-03-26 07:56:49
阅读次数:
126
控制杆类public class Lever {
protected int lever = 1;
public Lever()
{
lever = 1;
}
public Lever(int lever)
{
this.lever = lever;
}
public int getLever()
{
return lever;
}
public ...
分类:
编程语言 时间:
2016-03-26 07:55:38
阅读次数:
644
package dplearn;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Learn {
public static void main(String[] args){
List myList=new ArrayList();
Basicinf...
分类:
编程语言 时间:
2016-03-26 07:53:30
阅读次数:
143