
c++
c++基础知识
轻舟 /
这个作者很懒,什么都没留下…
展开
-
c++学习笔记:设计一个向量类,并重载运算符使两个向量可以相加减
向量类#include <iostream>using namespace std;class Vector{public: friend ostream &operator<<(ostream &cout, const Vector &vec); Vector(); void Set_vec();//设置向量 void Set_n();//设置维数 Vector operator+(Vector &v)原创 2020-05-19 21:56:34 · 1945 阅读 · 0 评论 -
c++运算符重载(常用运算符)知识点
c++运算符重载先给出一段代码,具体函数内容会在下面给出:class Person{public: Person(){} bool operator==(Person &p);//重载"==" bool operator!=(Person &p);//重载"!=" Person &operator++();//前置++重载 Person operator++(int);//后置++重载 friend ostream &op原创 2020-06-28 23:41:50 · 461 阅读 · 0 评论 -
c/c++笔记:将一个整型数组里的元素倒置
int main(){ const int N = 6; int nums[N] = {1,2,3,4,5,6}; for(int j = 0; j < N; j++){ for(int i = 0; i < N-1-j; i++){ int temp = nums[i]; nums[i] = nums[i+1]; nums[i+1] = temp; } }原创 2020-06-20 23:41:38 · 4481 阅读 · 0 评论 -
c++学习笔记:数组排序模板函数
#include <iostream>using namespace std;template<typename T, int n>void Sort(T (&a)[n])//此处n的大小由编译器推断{ int len = sizeof(a) / sizeof(*a);//获取数组中元素的个数 { for(int i = 0; i < len - 1; i++)//冒泡排序 { for(i原创 2020-05-31 16:02:06 · 377 阅读 · 0 评论