C++ Basic Knowledge

Things won't make sense the first time you see them, and that's perfectly normal. Keep practicing and you'll get there.

 

1. OP: 基于过程,系统由一个个逻辑过程组成,每个过程密不可分
  + 数学应用题的解答方式
  + 面向对象思路对解决数学问题有没有启发
OO:系统由一系列对象及其关联组成,对象间独立性较好,各司其职(人体,人类社会,地球etc.复杂系统都是基于这种模式构建)

OO和OP其实相互迭代和嵌套

分析问题两种思维方式

语言永远是一种你用来实现想法的工具,核心还是你的想法

 

2. C-Language变量:
2.1 生存期 - 存储类型说明
  + 静态或动态两种方式存储
2.2 作用域(space) 
  + local variable: 函数实参,函数内部声明的变量
  + global variable: 函数外部声明的变量,当先于使用该变量的函数之前定义时可直接使用,当在函数使用之后定义的global variable要使用extern全局变量说明符,e.g.: extern variable1;

 

3. C++ 编译
预编译(欲处理):宏定义,文件包含,条件编译

pre_compile insturction
#define // replace when pre_compile, no other check

typedef     // handle when compile, 给一个已经存在的类型一个别名

3.1 条件编译(提高程序通用性)
#ifdef | #ifndef ConstantsName
Commands
    [#else Commands]
#endif
e.g.1
#ifdef WINDOWS    // ID defined with #define ***
#define MYTYPE long
#else
#define MYTYPE float
#endif

e.g.2
#define DEBUG  // this row like a switch
#ifdef DEBUG
print ("driver_ok");
#endif

 

4. Overload : functions have the same name but the parameters are different

  + Override : Rewrite the virutal method inherted from parent class

 

5. C & C++ 混合编程

5.1  extern "C"的真实目的是实现类C和C++的混合编程。在C++源文件中的语句前面加上extern "C",表明它按照类C的编译和连接规约来编译和连接,而不是C++的编译的连接规约。这样在类C的代码中就可以调用C++的函数or变量等。(注:类C,代表的是跟C语言的编译和连接方式一致的所有语言)

5.2 - C++ references C code

* cHeader.h

#ifndef C_HEADER
#define C_HEADER

void print(int i);

#endif

*cHeader.c

#include <stdio.h>
#include "cHeader.h"

void print(int i){
    printf("i*i=%d \n", i*i);
}

*cppMain.cpp

extern "C"{
#include "cHeader.h"
/}

int _tmain(int argc, _TCHAR* argv[])
{
    //printf("Hello World");
    print(3);
    return 0;
}

5.3 - C references C++ code

* cppHeader.h

#ifndef CPP_HEADER
#define CPP_HEADER
#define __cpluscplus

#ifdef __cplusplus
extern "C" {
#endif

void print(int i);

#ifdef __cplusplus
}
#endif
#endif

*cppHeader.cpp

#include "cppHeader.h"
#include <iostream>
using namespace std;

void print(int i){
    cout<<"i*i="<<i*i<<endl;
}

*cMain.c

//extern void print(int i);

int main(int argc, char** argv){
    print(3);
    return 0;
}

6. function ptr

typedef int (*FT) (const void* ,const void*),表示定义了一个函数指针的别名FT,这种函数指针指向的函数有这样的特征:返回值为int型、有两个参数,参数类型可以为任意类型的指针(因为为void*)

最典型的函数指针的别名的例子是,信号处理函数signal,它的定义如下:
typedef void (*HANDLER)(int);
HANDLER signal(int ,HANDLER);

 

7.

 

原文链接: https://www.cnblogs.com/sytjs/archive/2011/11/26/2264164.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++ Basic Knowledge

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/37294

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 下午1:58
下一篇 2023年2月8日 下午1:58

相关推荐