C++ primer plus V6 泛读知识点

2018-08-17  本文已影响0人  _layty

2018年8月17日 22:14:16


title: C++PrimerPlus读书笔记
typora-root-url: ..
typora-copy-images-to: ..\img\root
date: 2018-08-15 22:55:29
tags:
c++
学习
categories:
学习


C++PrimerPlus读书笔记

第一章

第二章

第三章

第四章

//声明结构类型
struct ab{
int a;int b;
}
//c这样声明变量
struct ab tmp1;
//c++  可以省略struct
ab tmp2;
//还有以下用法

struct structName
{
    int a ; int b;
}tmpname;
当有tmpname的时候可以省略structName,这样只能用一次,这时候还可以直接初始化.
struct 
{
    int a ; int b;
}tmpname={0,1}

//还可以这么赋值,c99以后支持的,韦东山有讲
tmpname={.b=xxx;.a=xxx}

#include <stdio.h>
 
struct person
{
    char    *name;
    union
    {
        char gender;
        int  id;
    };
    int      age;
};
 
int main(void)
{
    struct person jim = {"jim", 'F', 28};
 
    printf("jim.gender = %c, jim.id = %d\n", jim.gender, jim.id);
 
    return 0;
}
short tell[10];
cout<<tell<<endl;
cout<<&tell<<endl;
//从地址上看两者是相等的,但是&tell[0]=tell是一个2字节的内存地址,&tell是一个20字节的地址,所以tell+1是地址加2,&tell+1是加了20,
//可以这么来一个指针 
short (*p) [20]=&tell;

第五章

第六章

第七章

int data[3][4]={{1,2,3,4},{2,2,3,4},{3,2,3,4}};
int total=sum{data,3}

//原型
int sum(int (*pt)[4],int size)//这里(*pt)要有括号,否则就是 pt[4] 然后是个int 指针,是个指针数组了
//或者
int sum(int pt[][4],int size)
f1(const double ar[],int n)
f2(const double [],int )
f3(const double *,int )  
///都忽略参数

//step1
//pt是个指针,指向一个函数,
double (*pt)(int)
//pt是个函数,返回一个 double*
double * pt(int) 
    
//step2
// pt是个函数,返回值为 double *
const double * pt(const double *,int)
//pt是个指针,指向一个返回值为 double*的函数
const double * (*pt)(const double* ,int)
    
//step3
//[]优先级高于*,所以pt是个数组,类型为*,也就是是个指针的数组,数组里存的是指针,指向了一个函数
const double * (*pt[3]) (const double* ,int)
    
//step4
//构造一个指针,指向step3,简单的理解就是将pt改为(*pt1)就ok,pt1指向step3的数组
//1.pt是个指针  (*pt)
//2.指向一个数组 (*pt)[3]
//3.该数组的类型是个指针,我们定义一个数组,数组的元素类型为 int* 的话,这么定义  int* a[3];
    //同上,    (type)* (*pt)[3] 也就是↓
const double * (*(*pt)[3]) (double * ,int)

第八章

//下面都可以,class是老的
template <typename Anytype>//一般写作 template <typename T>
template <class Anytype>
void Swap(Antype &a, Anytype &b)
{
    Anytype temp;
    temp=b;
    b=a;
    a=temp;
}
//模板
template<typename T>
void Swap(T &a, T &b);

struct job
{
    int a;
    int b;
}

//显示化声明,这里的Swap(Job)中的job是可选的,参数里面已经有了
//可以简写 template<> void Swap(job &j1, Job & j2);
template<> void Swap(Job)(job &j1, Job & j2);

//显示化定义
template<> void Swap(Job)(job &j1, Job & j2)
{
    .....
}

第九章

todo

==数组名取地址==

for里面的作用域

备忘:

上一篇 下一篇

猜你喜欢

热点阅读