![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
cpp
lslsyqyq
学习中……
展开
-
C++类属性为什么不直接操作(存取)
why 属性要设置成private 而不是public,存取要用相应接口(函数 方法)原创 2011-08-11 14:50:01 · 776 阅读 · 0 评论 -
c++优先级(来自http://www.cppreference.com)
原文地址 http://en.cppreference.com/w/cpp/language/operator_precedence The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending prec转载 2012-04-21 10:07:46 · 1084 阅读 · 0 评论 -
指针和数组
《C专家编程》里10.5节—使用指针向函数传递一个多维数组。 方法一,函数是 void fun(int arr[2][3]); 这种方法只能处理2行3列的int型数组。 方法二,可以省略第一维的长度。函数是 void fun(int arr[][3]); 这种方式虽然限制宽松了一些,但是还是只能处理每行是3个整数长度的数组。 或者写成这种形式 void fun(int (转载 2012-06-12 13:06:12 · 393 阅读 · 0 评论 -
vector执行insert或erase后迭代器应该重新获取
书上看到: vector执行insert或erase后迭代器应该重新获取, 这是为什么呢? 因为执行insert以后可能内存重新分配了,原先的迭代器自然也就失效了。 代码片段: vector array; array.reserve(5); //修改容量为5, 若容量小于5,则该段程序将崩溃 cout<<array.capacity()<<endl; int ii=0;原创 2012-07-05 08:48:14 · 2763 阅读 · 0 评论 -
快排递归非递归
#include using namespace std; int partition(int *a, int l, int h) { int x = a[l]; int i = l; int j = h+1; int temp; while (i<j) { while (a[++i]<x&&i<h); while(a[--j]>x); if (i<j) {转载 2012-06-28 16:23:56 · 3973 阅读 · 0 评论 -
简单的背包问题(非递归和递归)
问题描述:从一堆物品中选出满足特定要求的数个物品,求方案 从重量1 4 4 5 7的5个物品中选出数个,要求总重量为10 分析:略 递归算法: int knap(int w[], int t, int n) { if(t==0) return 1; else if(t0&&n<1) return 0; else if(knap(w,t-w[n-1],n-转载 2012-06-29 13:47:43 · 1053 阅读 · 0 评论 -
私有变量
私有变量仅在类型内部可以访问,以前一直理解成只能同个实例访问自己内部的,原来只要类型相同就可以了 如下assign函数中,x.value,x是参数,虽然value是私有类型,但是在相同类型内部就都可以访问。 template class MyClass { T value; public: MyClass(T t):value(t){} void assign( MyClass x)原创 2013-06-14 14:45:39 · 514 阅读 · 0 评论 -
静态成员变量的定义
可以在类外定义或者在类内定义,因为是常量,只能定义一次。 template class MyClass { T value; public: string str; MyClass(){str="";} MyClass(const MyClass& t) // 复制构造函数 { str = ""; value = t.value; cout<<"copy原创 2013-06-14 15:55:32 · 661 阅读 · 0 评论 -
c语言ftell和c++的tellg,返回读写偏移
背景 解析wav格式,发现某个文件解析错误,调试发现,打开文件时,文件偏移是0,读取4字节后,文件偏移是3588,不知道为什么。 奇怪的是换成别的文件,文件偏移就正常,代码一模一样,只是换了个wav文件名。 使用c语言写了一遍,依然一样,换成qt后,读4个字节,偏移位置就是4,正常。 那么ftell和tellg到底是什么意思呢? 为什么对这个特定的文件会有这样的表现? char原创 2017-07-07 07:50:44 · 1380 阅读 · 0 评论