有关const成员、static成员、const static成员的初始化:
1、const成员:只能在构造函数后的初始化列表中初始化
2、static成员:初始化在类外,且不加static修饰
3、const static成员:类只有唯一一份拷贝,且数值不能改变。因此,可以在类中声明处初始化,也可以像static在类外初始化
#include
using std::cout;
...
分类:
编程语言 时间:
2014-07-11 08:16:29
阅读次数:
299
#include
#include
#include
#include
#include
using namespace std;
#define point Point
const double eps = 1e-8;
const double PI = acos(-1.0);
double ABS(double x){return x>0?x:-x;}
int sgn(double x){...
分类:
其他好文 时间:
2014-07-10 23:54:16
阅读次数:
253
11237 - Halloween treats
题目链接
题意:有c个小伙伴,n个房子(c ai个糖果,要求选一些房子,使得得到的糖果能平均分给小伙伴,输出方案
思路:c
代码:
#include
#include
const int N = 100005;
int c, n, a[N], sum[N], vis[N];
void solve() {
...
分类:
其他好文 时间:
2014-07-10 23:46:23
阅读次数:
256
旧式转型
(T) expression 或 T (expression)
新式转型
const_cast(expression)
通常被用来将对象的常量性转除(cast away the constness)
dynamic_cast(expression)
执行“安全向下转型”,也就是用来决定某对象是否归属继承体系中的某个类型。
reinterpret_cast(expression)
执行低级转型 //不太懂??
static_cast(expression)
强迫隐式转换
...
分类:
编程语言 时间:
2014-07-10 23:19:18
阅读次数:
250
题意:求最大的三角形
思路:先初始化从左到右和从右到左的最大连续的‘-’,然后就是当奇数列的时候找头向下的三角形,偶数的时候相反找
#include
#include
#include
#include
using namespace std;
const int MAXN = 200;
char map[MAXN][MAXN];
int Left[MAXN][MAXN], Rig...
分类:
其他好文 时间:
2014-07-10 22:09:52
阅读次数:
272
1. 基于 const的重载
为了解决这个问题,我们必须定义两个display 操作:一个是const,另一个不是const。基于成员函数是否为const,可以重载一个成员函数;
同样地,基于一个指针形参是否指向const(第7.8.4 节),可以重载一个函数。const对象只能使用const 成员。
非const 对象可以使用任一成员,但非const 版本是一个更好的匹配。 在此,我们将...
分类:
编程语言 时间:
2014-07-10 22:09:07
阅读次数:
228
题目链接:点击打开链接
需要注意的是镜子在与2个人共线时是不作为障碍物,但其他情况与墙一致
#include
#include
#include
#include
#include
using namespace std;
#define point Point
const double eps = 1e-8;
const double PI = acos(-1.0);
double ABS(...
分类:
其他好文 时间:
2014-07-10 21:32:50
阅读次数:
254
1. 以下三条输出语句分别输出什么?
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
cout
c...
分类:
其他好文 时间:
2014-07-10 20:41:30
阅读次数:
248
在函数 int ArgFunc(const int *str, ...) 含有可变参数的函数中, 获取 可变形参函数中的参数...
分类:
编程语言 时间:
2014-07-10 19:56:29
阅读次数:
242
经验:尽可能延后变量定义式的出现。这样做可增加程序的清晰度并改善程序效率。
示例:
//这个函数过早定义变量“encrypted”
std::string encryptPassword(const std::string &password){
using namespace std;
string encrypted;
if(password.length() < MinimumPasswordLength){
throw logic_error("Password is too short"...
分类:
编程语言 时间:
2014-07-10 19:27:30
阅读次数:
253