最近晚上开始看c++相关资料,网上找到一个侯捷2016年的视频,抽看看了下获益良多.现整理记录相关知识点。
iostream与iostream.h的区别
When including a header file in C++, what's the difference between...
1) including the .h versus not including the .h when wrapping it in < > signs?
#include <iostream> vs. #include <iostream.h>
2) wrapping the header name in double quotes versus wrapping it in < > signs?
#include <iostream.h> vs. #include "iostream.h"
answer,来源于stackoverflow
iostream.h is deprecated - it is the original Stroustrup version, and iostream is the version from the standards committee. Generally compilers point them both to the same thing, but some older compilers won't have the older one. In some odd cases they will both exist and be different (to support legacy code) and you then must be specific.
versus <> simply means check the local directories for the header before going to the library (in most compilers).
友元
下面的例子用于说明:相同class的各个objects互为friend友元。
#include <iostream>
using namespace std;
/*相同class的各个objects互为friend友元*/
class complex
{
public:
complex(double r = 0,double i = 0):re(r),im(i)
{ }
int func(const complex & param)
{
return param.re + param.im;
}
private:
double re,im;
};
int main()
{
complex c1(2,1);
complex c2;
int sum = c2.func(c1);
cout << "sum = "<<sum<<endl;
return 0;
}
class经典分类
class without pointer member(s)
complex类
class with pointer member(s)
string类
老王 求 c++资料分享~~