C++ Primary

43 篇文章 0 订阅

001:注意,在C语言中,struct 定义的结构体,在使用的时候需要将它显视的写出来,而C++中,struct和class关键字在定义变量的时候可以省略。

002:C++中,struct默认所有成员存取说明是public的,同一种说符可以在结构中多次出现,这样就不一定非要将所有共有的放在一起,所有的私有的放在一起了。

003:友元函数,不论在私有部分声明还是共有部分,都是一样的,即:有完全的权限去访问类的所有成员。

004:类的所有成员都可以变成另一个类的友元。

005:struct 默认继承是共有,内部成员默认也是共有;class默认继承是似有,内部成员默认也是私有。

006:C++中的类可以多继承,JAVA中的类只能单继承,不要弄混淆了。

例如:

#include<iostream>
using namespace std;

class one
{
public:
	one(){cout << "one" << endl;}
};

class three
{
public:
	three(){cout << "three" << endl;}
};

class two:public one, three
{
	int b;
public:
	two(int j)
	{
		b = j;
		cout << "two" << endl;
	}
};

int main()
{
	two o(20);
	cout << "main" << endl;
	return 0;
}

007:虽然不允许声明含有纯虚函数的类的实例,但是可以声明含有纯虚函数的类的指针,这样对于运行时多态性是很有必要的。
008:

重载操作符号

bool operator <(const Time & a,const Time & b){return false;}
bool operator >(const Time & a,const Time & b){return false;}
Time operator +(Time a,Time b)
{
Time t;
t.hour = a.hour + b.hour;
return t;
}
istream & operator >>(istream & is,Time & t)
{
	return is>>t.date>>t.time;
}

ostream & operator <<(ostream & os,Time & t)
{
	return os<<t.date<<" "<<t.time;
}




 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值