
c++
努力的coder
坚持,为了梦想,一步又一步地往前走。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
c++中的常引用
常引用是只读的引用 #include <iostream> #include <cmath> using namespace std; class Point{ public: Point(int x=0, int y = 0):x(x),y(y){} int getX(){return x;} int getY(){return y;} //友元函数 ...原创 2019-07-08 21:51:39 · 419 阅读 · 0 评论 -
c++指针
#include <iostream> using namespace std; int main() { int array[3] = {1,2,3}; int *p;//定义指针 for(p = array; p < array+sizeof(array)/sizeof(int); ++p){ *p += 2; std::cout << *p ...原创 2019-07-10 14:38:38 · 92 阅读 · 0 评论 -
c++基本语法
//基本输入输出 #include <iostream> // 引入操作符头文件 #include <iomanip> //使用标准名称空间中的变量名,不引入时,得这么写:std::cout << std::hex<< 3.4<< std::endl; using namespace std; int main() { ...原创 2019-06-30 11:57:03 · 589 阅读 · 0 评论 -
动态内存分配与释放
动态内存分配 #include <iostream> using namespace std; class Point{ public: //默认值的构造函数 Point():x(0),y(0){ cout << "Default Constructor called." <<endl; } //自定义构造函数 Point(int ...原创 2019-07-10 21:05:27 · 279 阅读 · 0 评论 -
数组对象
#include <iostream> using namespace std; #include <vector> double average(const vector<double> &arr);//函数声明 int main() { unsigned n; cout << "n = "; cin >> n; v...原创 2019-07-10 21:31:04 · 154 阅读 · 0 评论 -
基于范围的for配合auto举例
#include <iostream> using namespace std; #include <vector> int main() { vector<int> v={1,2,3};//创建数组对象 for(auto i=v.begin(); i != v.end(); ++i){ cout << *i << endl;...原创 2019-07-10 21:38:01 · 195 阅读 · 0 评论 -
对象的浅层复制和深层复制
浅层复制:实现对象间数据元素的一一对应复制。 深层复制:当被复制的对象数据成员是指针类型时,不是复制该指针成员本身,而是将指针所指对象进行复制。 //浅层复制 #include <iostream> #include <cassert> using namespace std; class Point { public: Point() : ...转载 2019-07-10 22:46:27 · 474 阅读 · 0 评论