
c++
风云159
这个作者很懒,什么都没留下…
展开
-
8.友元函数友元类
#include<iostream>#include<cmath>using namespace std;class Point;class PointManager { double getDistance(Point& x1, Point& x2);};class Point {public: Point(int x) { this...原创 2018-05-31 16:31:08 · 272 阅读 · 0 评论 -
7.this指针
#include<iostream>using namespace std;class Test {public: Test(int k) :m_k(k) { }; ~Test() { delete this; } int get_k() const { /* this是一个常指针 Test* const this,说明不可以修改this指向的地址, 但...原创 2018-05-31 15:27:39 · 146 阅读 · 0 评论 -
6.函数指针
#include<iostream>using namespace std;/* 函数指针,三种方式*/int f(int a, int b){ return a + b;}//方法一:声明一个函数类型typedef int(myFun1)(int, int);//方法二:声明一个函数指针类型typedef int(*myFun2)(int, int);//最常...原创 2018-05-30 20:15:17 · 158 阅读 · 0 评论 -
5.字符串常量
#include<iostream>#include<vector>using namespace std;//1.每个字符串常量都是一个地址,这个地址是指字符串首元素地址//2.字符串常量放在data区(文字常量区),内容是只读的,不可修改void fun() { printf("%p\n", "hello word");//01398BD2}int ma...原创 2018-05-30 10:38:09 · 597 阅读 · 0 评论 -
4.形参中的数组是指针变量
#include<iostream>using namespace std;/* 形参中的数组,不是数组,是指针(对应数据首元素地址,用sizeof获取的是指针大小,而不是数组大小) 形参数组:int a[100], int[a], int *a 对编译器而言是一样的,都当做int *处理*/void f(int a[100]){ cout << sizeof...原创 2018-05-29 21:48:30 · 960 阅读 · 0 评论 -
3.const修饰指针
#include<iostream>using namespace std;//const修饰的指针int main(){ int a = 10; //const int *p 和int const *p 是一样的。 //const修饰的是 *,表明指针所指向的地址中的数据不可修改,但可以修改指针所指向的地址 const int *p = &a; int con...原创 2018-05-29 19:46:48 · 194 阅读 · 0 评论 -
2.万能指针
#include<iostream>using namespace std;/***万能指针**/int main(){ //1.不可以定义void类型的普通变量,不能确定类型 //void a; //2.可以定义void* 变量,也叫万能指针,可以指向任何类型的变量 // 但是使用该指针所指向的内存时,需要把该指针转化成对应类型 void* p = NULL;...原创 2018-05-29 19:25:36 · 261 阅读 · 0 评论 -
1.指针大小
#include<iostream>using namespace std;int main() { //32位编译器用32位(4字节)大小保存地址 //64位编译器用64位(8字节)大小保存地址 int a = sizeof(int*); int b = sizeof(char*); double* p; int c = sizeof(p); //指针大小是一样的...原创 2018-05-29 17:06:38 · 383 阅读 · 0 评论 -
9.重载操作符
#include<iostream>#include<cmath>using namespace std;class Num {public: Num(int a) { this->a = a; } void print() { cout << a << endl; } //也可以在内部提供一个+号操作符重载,但和全...原创 2018-06-01 09:41:33 · 197 阅读 · 0 评论