
c++
iteye_15479
这个作者很懒,什么都没留下…
展开
-
volatile的含义
指一个变量可能随时由于外界地变化而变化 例如有两个线程分别是线程1和线程2 一个全局变量volatile int i = 0; 线程1 执行如下代码 while(i == 0); printf(); 假设线程1执行到 while处,就会反复执行上这条语句 此时线程2执行 i = 1; 线程1就会执行 printf() 若没有指定 int i 为 vo...原创 2010-01-04 14:39:29 · 103 阅读 · 0 评论 -
c++ int&
float a = 1.0f;cout << (int)a << endl;cout << (int&)a << endl;cout << boolalpha << ( (int)a == (int&)a ) << endl; // 输出什么?float b = 0.原创 2009-09-20 16:19:32 · 270 阅读 · 0 评论 -
stl vector erase
vi a.cpp#include <iostream>using namespace std;#include <vector>#include <string>typedef unsigned short WORD;int main(){ vector<string> vStr; vS...原创 2009-09-20 16:39:32 · 89 阅读 · 0 评论 -
Use Protected Constructors to Block Undesirable Object Instantiation
Use Protected Constructors to Block Undesirable Object InstantiationIn order to block creation of class instances, you can declare its constructor as protected. class CommonRoot { protected: C...原创 2009-09-20 21:35:30 · 97 阅读 · 0 评论 -
printf 函数 格式
printf()函数是格式输出函数,请求printf()打印变量的指令取决与变量的类型.例如,在打印整数是使用%d符号,在打印字符是用%c 符号.这些符号被称为转换说明.因为它们指定了如何不数据转换成可显示的形式.下列列出的是ANSI C标准peintf()提供的各种转换说明. 转换说明及作为结果的打印输出%a 浮点数、十六进制数字和p-记数法...原创 2009-09-20 21:48:41 · 203 阅读 · 0 评论 -
STL vector and list Difference
If you are using STL fist time , you can see that these are the classes for holding a gropup of things.You need toinclude #include <vector> and #include <list> for usingthese c...原创 2009-09-22 10:16:13 · 86 阅读 · 0 评论 -
C++ - Calling virtual function from constructor
<!-- X-Subject-Header-End--><!-- X-Head-of-Message-->From: Rob Newberry <robnewberry at grouplogic dot com>To: Eddy Ilg <eddy at fericom dot net>Cc: gcc-help ...原创 2009-09-22 10:17:01 · 250 阅读 · 0 评论 -
堆与栈的区别
一、预备知识—程序的内存分配 一个由c/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。 2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表,呵呵。 3、全局...原创 2009-09-23 11:48:01 · 87 阅读 · 0 评论 -
copy constructor and copy assignment
When copies of objects are madeA copy constructor is called whenever a new variable is created from an object. This happens in the following cases (but not in assignment).A variable is declared...原创 2010-07-06 20:47:48 · 231 阅读 · 0 评论 -
deep copy & shallow copy
A shallow copy of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The p...原创 2010-07-06 20:57:01 · 151 阅读 · 0 评论 -
c++ dynamic binding
Good tutorial about c++ dynamic binding原创 2010-07-06 21:20:39 · 132 阅读 · 0 评论 -
how to reverse the word sequence in a sentence?
For example, &quot;Welcome you to Beijing&quot; is reversed into &quot;Beijing to you Welcome&quot; void ReverseString(char *s, int start, int end) 2{ 3 while (start < end)...原创 2010-07-06 22:01:45 · 98 阅读 · 0 评论 -
Test performance of allocating a zeroed file via various methods
/* * Test performance of allocating a zeroed file via various methods on * various file systems * * Copyright (C) 2009 Red Hat Inc. * Author(s): Amit Shah * * This program is f...原创 2010-08-07 22:09:37 · 100 阅读 · 0 评论 -
How to use fallocate system call
/* * fallocate - utility to use the fallocate system call * * Copyright (C) 2008 Red Hat, Inc. All rights reserved. * Written by Eric Sandeen <sandeen@redhat.com> * * cvtnum routine ...原创 2010-08-07 22:19:05 · 327 阅读 · 0 评论 -
errno.h
查看错误代码errno是调试程序的一个重要方法。当linuc C api函数发生异常时,一般会将errno变量(需include errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。在实际编程中用这一招解决了不少原本看来莫名其妙的问题。比较麻烦的是每次都要去linux源代码里面查找错误代码的含义,现在把它贴出来,以后需要查时就来这里看了。以下来自linux 2...原创 2010-08-10 08:46:53 · 128 阅读 · 0 评论 -
lost on Py_DECREF/INCREF when handling PyList_Append in Python C extension
The main hint is in the docs, if it says 'Steals a reference' than the function basically takes ownership, if it says 'New Reference' than it did an INCREF for you, if nothing is said it probably does...原创 2015-11-03 21:41:16 · 303 阅读 · 0 评论 -
Java的Generics和c++的Template到底有什么不同?
先了解Java的Generics:根据Java的文档,Java引入Generics一是为了在编译时提供更强的类型检查,二是为了泛型编程。编译时,Java靠type erasure来实现Generics:1. 将所有的泛型参数替换为限定(bound这里如何翻译?)的类型,如果没有限定,就替换为Object类。因此然生的字节码和普通的类文件一样;2. 为了保证类型安全,必要的...2012-12-27 16:21:50 · 276 阅读 · 0 评论 -
c++中的virtual inheritance
[url]http://stackoverflow.com/questions/21558/in-c-what-is-a-virtual-base-class[/url]主要是为了避免歧义。原创 2014-01-27 10:20:19 · 189 阅读 · 0 评论 -
c++ 字符串
using namespace std;#include <iostream>int main(){char * boolalpha = "hello:";char str1[] = "abc";char str2[] = "abc";const char str3[] = "abc";const char str4[] = "a...2009-09-20 15:21:53 · 109 阅读 · 0 评论 -
理解UNIX系统的signal函数的定义
读《unix环境高级编程》信号机制一章,遇到signal函数: #include<signal.h> void (* signal (int signo, void (*func) (int) )) (int ); 返回值:成功返回信号以前的处理配置,出错返回SIG_ERR....2009-07-23 22:26:53 · 158 阅读 · 0 评论 -
最长公共子串问题解答
编写一个程序,对输入的字符串s和t,求其最长的公共子字符串。 【输入形式】 从屏幕分行读入串s和t。s和t由任意字符构成,长度都不超50个字符。输入数据确保只有唯一的最长公共子串。如果没有公共子串,打印No Answer 【输出形式】 在单独行上输出串s和串t的最长公共子串,在结尾输出一个回车符。 //作者:baihacker//时间:9.12.2006 #...原创 2010-01-04 15:48:19 · 1230 阅读 · 0 评论 -
Get information about CPU memory usage
#include <iostream>#include <iomanip>#pragma comment (lib, "psapi.lib") // Add 'psapi.lib' to your linker options #include <windows.h>#include <psapi.h> using nam...原创 2009-07-17 23:43:40 · 270 阅读 · 0 评论 -
CppUnit代码理解(1)
目前网上搜索到的讲CppUnit源码解读基本来源于晨光CppUnit源码解读,是很好的源码阅读笔记。但是针对的是 CppUnit1.8.0版,现在网上下载到的一般都比这个新了,我下载的是1.12.1版,代码有一些变动,就结合晨光的 笔记仔细看了一些源码。 首先看一下我们通常写的简单的测试类: class MyTest : public CppUnit::TestFixture { C...2009-07-17 23:58:36 · 170 阅读 · 0 评论 -
CppUnit代码理解(2)
看一个很重要的宏: CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MyTest, "alltest" ); 我也不清楚,先看宏定义吧,在HelpMacros.h里面: /** Adds the specified fixture suite to the specified registry suite.* \ingroup Creating...2009-07-19 21:29:06 · 229 阅读 · 0 评论 -
c++ 字节对齐
sizeof() & #pragma结构体的sizeof这是初学者问得最多的一个问题,所以这里有必要多费点笔墨。让我们先看一个结构体:struct S1{char c;int i;};问sizeof(s1)等于多少聪明的你开始思考了,char占1个字节,int占4个字节,那么加起来就应该是5。是这样吗你在你机器上试过了吗也许你是对的...原创 2010-01-05 10:46:28 · 96 阅读 · 0 评论 -
c++问答
1. Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible ?There is nothing like Virtual Constructor. The Constructor cant be virtual as the constructo...原创 2010-01-06 14:43:33 · 296 阅读 · 0 评论 -
常量字符串为什么位于静态存储区
http://hi.baidu.com/%D0%C7%BB%F0%D3%C4%C0%B6/blog/item/410174384e529ffbb211c71c.html原创 2010-09-13 22:41:28 · 113 阅读 · 0 评论 -
异或运算法则
1. a ^ b = b ^ a 2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c; 3. d = a ^ b ^ c 可以推出 a = d ^ b ^ c. 4. a ^ b ^ a = b.原创 2010-09-14 09:47:29 · 2260 阅读 · 0 评论 -
static全局变量与普通的全局变量有什么区别
static全局变量与普通的全局变量有什么区别?static局部变量和普通局部变量有什么区别?static函数与普通函数有什么区别? 答 、全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量。全局变量本身就是静态存储方式, ...原创 2010-02-08 11:27:18 · 241 阅读 · 0 评论 -
正整数分解算法
问题:将以正整数n表示成一系列正整数之和. n=n1+n2+n3+...+nk (n1>=n2>=n3>=nk>=1, k>=1)这就是正整数n的一个划分,正整数n不同的划分个数称为正整数n的划分数, 记作p(n)例如:6 有如下11种划分则p(6)=116;5+1;4+2, 4+1+1;3+3, 3+2+1, 3+1+1+1;2+2+2, 2+2+1+1, 2+...原创 2010-09-19 16:56:32 · 1236 阅读 · 0 评论 -
虚函数表又是怎样实现的?
每个含有虚函数的类有一张虚函数表(vtbl),表中每一项指向一个虚函数的地址,实现上是一个函数指针的数组。虚函数表既有继承性又有多态性。每个派生类的vtbl继承了它各个基类的vtbl,如果基类vtbl中包含某一项,则其派生类的vtbl中也将包含同样的一项,但是两项的值可能不同。如果派生类覆盖(override)了该项对应的虚函数,则派生类vtbl的该项指向重载后的虚函数,没有重载的话,则沿...原创 2010-09-20 22:01:13 · 287 阅读 · 0 评论 -
multiset usage as heap
Middle numberThere is a sequence of integers, we have two operations now1 add a: means add an integer a to the end of the sequence, forms a N+1 long sequence.2 mid : Output the current sequence'...原创 2010-09-24 21:37:05 · 94 阅读 · 0 评论 -
调整堆的算法
BeginadjustHeap(A[], i) // Heapify takes in our heap and index of current root node of subtree to be heapified{left=leftChild();right=rightChild();largest=i;if left<=A.heap-size AND A[l...原创 2010-09-25 10:34:35 · 354 阅读 · 0 评论 -
虚继承
http://www.cppblog.com/franksunny/archive/2008/10/16/64168.html原创 2010-09-26 09:03:57 · 65 阅读 · 0 评论 -
code snippet
char temp[3];char temp2[3];int a[100];void split(int m, int n, int a[], int index){ if(m!=0){ a[index]=m; if(index-1>=0 && a[index]<a[index-1]) return; index++;...原创 2010-09-27 08:31:14 · 91 阅读 · 0 评论 -
字符串指针、字符数组的sizeof和strlen结果
int main(){ char *p1="china"; char p2[]="china"; char p3[100]={0}; strcpy(p3, "china"); cout << sizeof(p1) << endl; cout << sizeof(p2) << endl; cout &原创 2010-09-27 08:36:13 · 180 阅读 · 0 评论 -
Calculating Permutations and Job Interview Questions
http://www.bearcave.com/random_hacks/permute.html Calculating Permutations and Job Interview Questions原创 2011-06-18 17:44:51 · 94 阅读 · 0 评论 -
An Example of Using std::tr1::bind
[code="c++"]#include #include using std::tr1::bind;using std::tr1::function;using std::tr1::placeholders::_1;using std::tr1::placeholders::_2;class CTest{ public: ...原创 2014-03-10 16:49:28 · 150 阅读 · 0 评论