随笔分类 - C++
记录C++的基础知识和易混知识
摘要:1 #include 2 #include 3 using namespace std; 4 5 template 6 void Make2DArray(Type **&x,int rows,int cols) 7 { 8 // 创建一个行指针 9 x=new Type *[ro...
阅读全文
摘要:1 // 使用模板和new创建2维动态数组 2 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 template10 bool Make2DArray(Type **&x,int rows,int c...
阅读全文
摘要:1 // 使用new动态分配存储空间 2 3 #include 4 using std::cout; 5 6 int main() 7 { 8 // 第1种方式 9 int *a=new int;10 *a=1;11 cout<<"使用第一种方式进行动态分配存储...
阅读全文
摘要:1 // 使用new动态分配存储空间 2 3 #include 4 using std::cout; 5 6 int main() 7 { 8 // 第1种方式 9 int *a=new int;10 *a=1;11 cout<<"使用第一种方式进行动态分配存储...
阅读全文
摘要:1 // 使用递归函数计算阶乘 2 3 #include 4 using namespace std; 5 int Factorial(int n); 6 7 int main() 8 { 9 cout>n;13 cout<<"n的阶乘n!= "<<Factorial(n)<...
阅读全文
摘要:下面使用模板递归函数计算一个数组中前n个元素之和: 1 // 使用模板函数递归计算前n个元素之和 2 3 #include 4 using namespace std; 5 template 6 Type Rsum(Type a[],int n) 7 { 8 if(n<=0) 9 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 // 通用模板计算一个表达式的值 4 template 5 Ta Abc(const Ta *a,const Tb *b,const Tc *c) 6 { 7 return (*a)+(*b)+(*c); 8 } 9 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 // 利用模板函数计算一个表达式 4 template 5 Type Abc(Type a,Type b,Type c) 6 { 7 return a+b+c; 8 } 9 // 利用引用参数指针计算一个表达式10 t...
阅读全文
摘要:下面以一个简单程序演示一下函数模板的使用: 1 #include 2 using namespace std; 3 template 4 Type Abc(Type a,Type b,Type c) 5 { 6 return a+b+c; 7 } 8 int main() 9 {10 ...
阅读全文
摘要:模板类以这样的代码开头:templateclass看作是变量的类型名,该变量接受类型作为其值,把Type看作是该变量的名称;将模板信息放在一个头文件中,建立stacktp.h 1 #ifndef STACKTP_H_ 2 #define STACKTP_H_ 3 // 建立模板 4 5 templ...
阅读全文
摘要:今天写下C++的第二章基础练习:2.6.1.C++程序的模块叫什么?解:函数用于创建C++程序的模块.2.6.2.下面的预处理器编译指令是做什么用的? #include解:该编译器指令导致预处理器将iostream文件的内容添加到程序中.预处理器处理以名称#开头的编译指令,他在编译程序时自动执行.2...
阅读全文

浙公网安备 33010602011771号