码迷,mamicode.com
首页 >  
搜索关键字:public    ( 82854个结果
public-private-protected-默认缺省 的区别
public 公共,加上这个修饰的属性和方法,可以在程序的任何其它地方访问 。private 私有,和public相反,加上这个修饰的属性和方法,只允许在本类中访问。protected 保护,位于public和private中间,加上这个修饰的属性和方法,只能在子类(extends)和同包下的程序访 ...
分类:其他好文   时间:2016-03-26 10:51:44    阅读次数:194
C++ String 写时拷贝
当类里面有指针对象时,采用简单的赋值浅拷贝,使得两个指针指向同一块内存,则析构两次,存在内存奔溃的问题,因此浅拷贝中利用引用计数。//引用计数浅拷贝classString { public: String(char*str="") :_str(newchar[strlen(str)+1]) ,_pRefCount(newint(1)) {} String(constS..
分类:编程语言   时间:2016-03-26 09:01:22    阅读次数:145
智能指针(模拟实现auto_ptr,shared_ptr,scooeptr 以及定制删除器c++ 实现)
#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
C++ - this指针
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
c++代码赏析之类对象传参
#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
Java第三次作业参考代码
控制杆类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
java 容器
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
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!