- 博客(22)
- 资源 (8)
- 收藏
- 关注
原创 C++ 基础函数模板、模板的 模板参数列表、模板参数列表中的类型模板参数 与 非类型模板参数
// ConsoleApplication20.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;//-- <>尖括号内是模板参数列表,模板参数列表中可以定义 类型参数,在这里T就是类型模板参数template<typename T>T addNum(T a, T b){ retu
2021-09-26 21:47:15 1192
原创 C++基础成员函数指针与成员变量指针
// ConsoleApplication19.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;class TC{public: static int ms_i; int m_i; int m_ii; void normalFunc(int){ cout << "成员函数" <
2021-09-26 19:13:19 277
原创 C++基础类型转换构造函数和类型转换函数(类型转换运算符)
// ConsoleApplication18.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;#define SPECIALCALL//-- 类型转换函数 存在二义性问题,编译不过。所以加了 #deiine SPECIALCALL控制class TestInt{public: //-- 类型转换构造
2021-09-26 15:04:09 135
原创 C++基础 多重继承引发的 虚基类与虚继承(基类被虚继承 就称为虚基类?)
//-- 不采用虚基类的方式classA.h#pragma once#include "grand.h"class A :public Grand{public: A(int a, int b, int c); ~A(); void testTongMingHanShu(); int m_iTingMIngBianLiang;private:};A::A(int a, int b, int c) :Grand(a){ printf("A的构造a= %d\n", a);}
2021-09-26 11:58:40 91
原创 C++ 基础多重继承
classA.h#pragma onceclass A{public: A(int i, int j, int k=1); ~A(); void testA();private:};classA.cpp#include "stdafx.h"#include "iostream"#include "classA.h"using namespace std;A::A(int i, int j, int k){ cout << "类A的构造函数" <<
2021-09-26 09:26:53 100
原创 C++基础左值和右值。 移动构造和移动赋值函数
classB.h#pragma onceclass B{public: B(); B(const B& b); ~B(); int m_bm;private:};classB.cpp#include "stdafx.h"#include "classB.h"#include "iostream"using namespace std;B::B() :m_bm(100){ //cout << "类B的构造函数被调用" << endl;
2021-09-25 21:14:18 135
原创 C++ 基础 友元函数、友元类、友元成员函数。以及两个头文件相互包含导致的超前引用问题
Men.h#pragma once#include "iostream"class A{ //-- 声明类B是类A的友元类,则B可以访问类A的所有成员了。 friend class B;private://public: int data;};class B{public: void callBAF(int i, A& a){ a.data = i; std::cout << "a.data=" << a.data << st
2021-09-15 23:17:29 521
原创 C++基础 封装 继承 多态、 父类的final关键字、子类的override关键字、构造 拷贝构造 析构的调用
Human.h#ifndef __HUMAN__#define __HUMAN__class HuMan{public: HuMan(char n[20], int a); //-- 一旦一个类 想要做父类,务必把这个类的析构函数写成虚函数。这样就能保证delete父类指针时能够调用正确的析构函数(即利用多态,先调用子类,再调用父类的析构函数) //-- 从而保证父类指针指向的子对象 内存被正确的释放。 virtual ~HuMan(); char name[20]; int age
2021-09-14 12:58:26 332
原创 C++基础 拷贝构造、运算符重载
Time.h#pragma once#include "iostream"#include "ExTimer.h"class Timer{public: Timer(); //-- 使用上的日常习惯: 单参构造,一般声明为显式的,拷贝构造一般不声明为explicit explicit Timer(int t); Timer(int h, int s, int m); ~Timer(); /* 叫做拷贝构造函数的构造函数:类的构造函数的第一个参数是类 类型的引用,假若有额外的参数,那
2021-09-14 00:29:26 107
原创 C++ 基础成员函数、显式的单参构造函数、c++11构造的特殊写法 const static mutable
Time.h#ifndef __MYTIME__#define __MYTIME__//#pragma once#include "iostream"#include "Player.h"using namespace std;class Time{public: //-- 成员函数的声明 void myPublicFunc(); Time(int hour, int min, int sec); //-- 单参构造,存在隐式类型转换的问题。在重载的构造函数中,将构造函数
2021-09-13 17:36:55 139
原创 C++基础多个.cpp文件,包含头一个.h文件 导致的重定义问题
myProject.h/*头文件声明: 防止单一 一个.cpp文件 在引用头文件时 会重复包含这个头文件。情况一:(比如a.cpp在 #include "myProject" 头文件的同时,又引入了一个 包含#include "myProject"的头文件, 在没有头文件卫士的情况下,会重复引入了myProject头文件,myProject头文件被引入了二次)当我们加入了头文件卫士后,把它分别引入在两个不同的app文件中, myFunc1.cpp 和 myFunc2.cpp中。在链接时 头文件中
2021-09-11 11:28:15 3356
原创 C++ 模板类vector<int> vi,以及模板迭代器vector<int>::iterator p = vi.begin();
// ConsoleApplicationC++jichu9.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"#include "string"#include "vector"using namespace std;/*字符串C中 char str[] {"Im ok!"};c++ string*///-- 字符数组的常用操作
2021-09-10 21:11:06 403
原创 C++基础常量指针与指针常量,数组指针与指针数组,const &作为函数形参可接受三种多样化的实参
// ConsoleApplicationC++jichu8.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;/*常量指针和指针常量常量指针: const char *p; 指针p指向的内容不可通过p来改变,指针本身可以变指针常量: char * const p; 指针p指向的内容可通过p来改变,指针本
2021-09-10 11:01:21 141
原创 C 读取配置文件/将结构体写入二进制文件/从二进制文件中读出结构体数据
// ConsoleApplicationCReaDFile.cpp : Defines the entry point for the console application.//#include "stdafx.h"//#include "cstdio"#include "cstring";//-- Error 3 error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s ins
2021-09-07 19:23:40 1609
原创 C++基础函数指针、数组指针 、const
// ConsoleApplicationC++jichu6.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;//-- 输出不同类型的地址void putAdress(){ //-- 输出字符类型的地址是一个字符串 char cc = 'a'; //printf(&cc); //getcha
2021-09-04 14:55:16 77
原创 C++基础静态局部变量、字符串、数组、引用(写一个不需要传参,利用引用和静态局部变量进行计数和还原的 函数)
// ConsoleApplicationC++jichu5.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;void swap(int &a, int&b){ int t = a; a = b; b = t;}//-- 不传入参数的计数器,并且能够清0//-- 返回的是地址in
2021-09-03 13:07:27 233
原创 C++基础函数、内存管理、结构体对象按照对象某个成员进行排序
// ConsoleApplicationC++jichu4.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "iostream"using namespace std;struct Date{ int year; int month; int day; void print(){ cout << year << ' ' <&
2021-09-03 12:00:53 127
原创 C++ 基础类型转换。最好不用强转,必须要转用以下4种
// ConsoleApplicationC++jichu3.cpp : Defines the entry point for the console application.//#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){ //-- static_cast int ia = static_cast<int>(12.346); int b = 100; void * p = &b; int *
2021-09-02 22:16:32 194 1
原创 C++ 基础命名空间、结构体、枚举、联合、头文件
// ConsoleApplicationC++jichu1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "cstdio" //可用c语言的标准库头文件#include "iostream"using namespace std; //标准库中的所有名字都放入一个名叫std的空间中。//-- 定义自己的命名空间namespace myProjName{ int
2021-09-02 21:43:28 194
原创 C++ 打印出每个字节的二进制
#include "stdafx.h"#include "iostream"using namespace std;//-- 依次打印出每个二进制位void showBits(int var){ //char 和 unsigned char 没有什么不同都是一个字节,唯一的区别是char的最高位是符号位-128~127,unsigned char 是0~255 typedef unsigned char uc; uc * p = (uc*)&var; printf("%s", ".
2021-09-02 10:58:50 2246
原创 C++类型符号位
// ConsoleApplicationTestCharOrUnsignedChar.cpp : Defines the entry point for the console application.//#include "stdafx.h"void testBits(unsigned char v){ //char 和 unsigned char 都是一个字节,唯一的区别的char有符号位-128~127 unsigned char是0~255 char c = v; unsigne
2021-09-02 10:14:30 405
原创 C++ decltype的使用
// ConsoleApplicationDecltype.cpp : Defines the entry point for the console application.///*decltype类型说明符,返回操作数的类型数据,在此过程中,编译器分析表达式并得到它的类型,却不实际计算表达式的值*/#include "stdafx.h"#include "typeinfo"//#include "stdio.h"#include "iostream"using namespace s
2021-09-01 13:32:52 331
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人