[源码下载] 不可或缺 Windows Native (23) - C++: 虚函数 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 虚函数 示例1.基类CppHuman.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppHuman { protected: string Name; public: // 我是虚函数 virtual string…
[源码下载] 不可或缺 Windows Native (20) - C++: 友元函数, 友元类 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 友元函数 友元类 示例演示友元函数, 友元类CppClass4.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppClass4 { public: string Demo(); }; } CppClas…
[源码下载] 不可或缺 Windows Native (6) - C 语言: 函数 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 函数 示例cFunction.h #ifndef _MYHEAD_FUNCTION_ #define _MYHEAD_FUNCTION_ #ifdef __cplusplus extern "C" #endif // 函数声明 // 像这种在 .h 中声明的函数,如果想被外部文件调用的话,则外部文件不用再声明即可调用 cha…
[源码下载] 不可或缺 Windows Native 系列文章索引 作者:webabcd 1.不可或缺 Windows Native (1) - C 语言: hello c 介绍不可或缺 Windows Native 之 C 语言 在 Windows Store Apps 中调用 C/C++ hello c 2.不可或缺 Windows Native (2) - C 语言: 常量,变量,基本数据类型 介绍不可或缺 Windows Native 之 C 语言 常量 变量 基本数据类型 3.不可或缺…
[源码下载] 不可或缺 Windows Native (22) - C++: 多重继承, 虚基类 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 多重继承 虚基类 示例1.基类 1CppBase1.h #pragma once #include <string> #include "CppBaseVirtual.h" using namespace std; namespace NativeDll { // virtual 代表 CppBase…
[源码下载] 不可或缺 Windows Native (16) - C++: 函数重载, 缺省参数, 内联函数, 函数模板 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 函数重载 缺省参数 内联函数 函数模板 示例1.函数重载, 缺省参数CppFunction1.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppFunction1 { publ…
[源码下载] 不可或缺 Windows Native (21) - C++: 继承, 组合, 派生类的构造函数和析构函数, 基类与派生类的转换, 子对象的实例化, 基类成员的隐藏(派生类成员覆盖基类成员) 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 继承 组合 派生类的构造函数和析构函数 基类与派生类的转换 子对象的实例化 基类成员的隐藏(派生类成员覆盖基类成员) 示例1.基类CppAnimal.h #pragma once #include <string>…
[源码下载] 不可或缺 Windows Native (25) - C++: windows app native, android app native, ios app native 作者:webabcd 介绍不可或缺 Windows Native 之 C++ windows app native android app native ios app native 示例一.演示 windows app native 开发1.native 层CppCx.h #pragma once #incl…
[源码下载] 不可或缺 Windows Native (24) - C++: 运算符重载, 自定义类型转换 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 运算符重载 自定义类型转换 示例CppOperator.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppOperator { public: string Demo(); }; } CppO…
[源码下载] 不可或缺 Windows Native (19) - C++: 对象的动态创建和释放, 对象的赋值和复制, 静态属性和静态函数, 类模板 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 对象的动态创建和释放 对象的赋值和复制 静态属性和静态函数 类模板 示例1.CppEmployee 类CppEmployee.h #pragma once #include <string> using namespace std; namespace NativeD…
[源码下载] 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象,  const 指针和指向 const 对象的指针, const 对象的引用 作者:webabcd 介绍不可或缺 Windows Native 之 C++ this 指针 对象数组 对象和指针 const 对象 const 指针和指向 const 对象的指针 const 对象的引用 示例1.CppEmployee 类CppEmployee.h #pragma…
[源码下载] 不可或缺 Windows Native (17) - C++: 类与对象 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 类与对象 示例1.类的设计CppEmployee.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppEmployee { int Number; // 默认为 private private: // 以下都是 p…
[源码下载] 不可或缺 Windows Native (15) - C++: 命名空间 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 命名空间 示例CppNamespace.h #pragma once #include <string> using namespace std; // 定义一个命名空间,并在其中定义一个类以及声明一个函数 namespace NativeDll { class CppNamespace { public: string Demo…
[源码下载] 不可或缺 Windows Native (14) - C++: 文件 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 文件 示例CppIO2.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppIO2 { public: string Demo(string rootPath); }; } CppIO2.cpp /* * 文件 */…
[源码下载] 不可或缺 Windows Native (13) - C++: 标准输入, 标准输出, 字符串内存流 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 标准输入 标准输出 字符串内存流 示例1.标准输入, 标准输出CppIO1.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppIO1 { public: string Demo();…
[源码下载] 不可或缺 Windows Native (12) - C++: 引用类型 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 引用类型 示例CppReference.h #pragma once #include <string> using namespace std; namespace NativeDll { class CppReference { public: string Demo(); }; } CppReference.cpp /* *…
[源码下载] 不可或缺 Windows Native (11) - C++: hello c++, C++ 与 C语言的区别小介 作者:webabcd 介绍不可或缺 Windows Native 之 C++ hello c++ C++ 与 C语言的区别小介 示例1.hello c++CppHello.h // 保证文件只被编译一次(即使被多次引用,也只被编译一次) /* * #ifndef 的方式依赖于宏名字不能冲突 * #pragma once 保证同一个文件不会被多次编译,这里的“同一个文件…
[源码下载] 不可或缺 Windows Native (1) - C 语言: hello c 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 在 Windows Store Apps 中调用 C/C++ hello c 示例1.演示如何在 Windows Store Apps(C#) 中调用 C/C++,需要新建 Windows Runtime Component(C++) 项目NativeDll/Simple.h /* * .h 头文件 */ // 保证文件只被…
[源码下载] 不可或缺 Windows Native (2) - C 语言: 常量,变量,基本数据类型 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 常量 变量 基本数据类型 示例cDataType.h #ifndef _MYHEAD_DATATYPE_ #define _MYHEAD_DATATYPE_ #ifdef __cplusplus extern "C" #endif char *demo_cDataType(); char *demo_co…
[源码下载] 不可或缺 Windows Native (3) - C 语言: 运算符,表达式,条件语句,循环语句,转向语句,空语句等 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 运算符 表达式 条件语句 循环语句 转向语句 空语句 示例1.运算符cOperator.h #ifndef _MYHEAD_OPERATOR_ #define _MYHEAD_OPERATOR_ #ifdef __cplusplus extern "C" #endif cha…
[源码下载] 不可或缺 Windows Native (4) - C 语言: 预处理命令,输入,输出 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 预处理命令 输入 输出 示例1.预处理命令cPreprocessor.h #ifndef _MYHEAD_PREPROCESSOR_ #define _MYHEAD_PREPROCESSOR_ #ifdef __cplusplus extern "C" #endif char *demo_cPreproce…
[源码下载] 不可或缺 Windows Native (7) - C 语言: 指针 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 指针 示例cPointer.h #ifndef _MYHEAD_POINTER_ #define _MYHEAD_POINTER_ #ifdef __cplusplus extern "C" #endif char *demo_cPointer(); #endif cPointer.c /* * 指针 */ #include…
[源码下载] 不可或缺 Windows Native (9) - C 语言: 动态分配内存,链表,位域 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 动态分配内存 链表 位域 示例cMemory.h #ifndef _MYHEAD_MEMORY_ #define _MYHEAD_MEMORY_ #ifdef __cplusplus extern "C" #endif char *demo_cMemory(); #endif cMemory.c /* *…
[源码下载] 不可或缺 Windows Native (10) - C 语言: 文件 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 文件 示例cFile.h #ifndef _MYHEAD_FILE_ #define _MYHEAD_FILE_ #ifdef __cplusplus extern "C" #endif char *demo_cFile(char *rootPath); #endif cFile.c /* * 文件 * * 从用户角度讲,…
[源码下载] 不可或缺 Windows Native (5) - C 语言: 数组 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 数组 示例cArray.h #ifndef _MYHEAD_ARRAY_ #define _MYHEAD_ARRAY_ #ifdef __cplusplus extern "C" #endif char *demo_cArray(); #endif cArray.c /* * 数组 * * * 定义数组,int ary[10…
[源码下载] 不可或缺 Windows Native (8) - C 语言: 结构体,共用体,枚举,类型定义符 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 结构体 共用体 枚举 类型定义符 示例cStruct.h #ifndef _MYHEAD_STRUCT_ #define _MYHEAD_STRUCT_ #ifdef __cplusplus extern "C" #endif char *demo_cStruct(); #endif cStruc…
也许之前我很少写代码,更很少写面向对象的代码,即使有写多半也很容易写回到面向过程的老路上去.在写面向过程的代码的时候,根本不管什么函数重载和覆盖,想到要什么功能就变得法子的换个函数名字,心里想想:反正函数重载本质也就是入栈了两个不同的函数. 回过头来讲,让我了解标题这三个概念的实际用处,还是在于我这第四次重写毕业论文的代码,将它改写成面向对象的时候,才理解的.在面向对象设计的过程中, 类是从抽象逐渐具体起来的,父类可以是非常非常抽象的东西,而最终实例化的子类就非常具体了.在这个继承的过程中,不断…
虚函数对于多态具有决定性的作用,有虚函数才能构成多态.上节的例子中,你可能还未发现虚函数的用途,不妨来看下面的代码. #include <iostream> using namespace std; //军队 class Troops{ public: virtual void fight(){ cout<<"Strike back!"<<endl; } }; //陆军 class Army: public Troops{ public: void…
前提条件:要明白在TWinControl有以下四个函数的存在,注意都是虚函数: procedure Invalidate; override;procedure Update; override;procedure Repaint; override; // 相当于前两句的组合procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; // 调用API显示 1个消息函数(图形控件没有相应的消息函数,除非程序员手动添加…
 上章链接: 22.C++- 继承与组合,protected访问级别 继承方式 继承方式位于定义子类的”:”后面,比如: class Line : public Object //继承方式是public { }; 继承方式默认为private 在C++中,继承方式共有3种: public继承 -指父类的成员(变量和函数)访问级别,在子类中保持不变 private继承 -指父类的成员,在子类中变为private私有成员. -也就是说子类无法访问父类的所有成员 protected继承 -指父类的pu…