
c++
文章平均质量分 56
hy0736
这个作者很懒,什么都没留下…
展开
-
c++ 虚函数
我们先来讨论一个类(Class)的存储配置。首先来写一个类,这个类没有任何数据成员,然后来看看他的内存结构。程序1:#include using namespace std;class Class{};int main(){ Class objClass; cout cout return 0;}程序输出:Size of objec转载 2012-06-03 22:05:00 · 364 阅读 · 0 评论 -
SetBitStream
// wData 是数据 用ncData 为来表示wData// int index = 0// index = SetBitStream(index,1,4); 0001 index变成4// index = SetBitStream(index,3,10) 0000000011 index变成14// 0001 0000原创 2013-01-10 10:28:54 · 575 阅读 · 0 评论 -
C++ 操作符重载的规则
-> () [ ] = 等操作符必须定义为类成员+- ++ 会改变对象的状态,通常定义为类成员+原创 2012-11-13 11:30:35 · 309 阅读 · 0 评论 -
_type_traits
#ifndef MY_TYPE_TRAITS_H#define MY_TYPE_TRAITS_H struct my_true_type {}; struct my_false_type {}; template struct my_type_traits{ typedef my_false_type has_trivial_destructo转载 2012-07-03 22:02:41 · 449 阅读 · 0 评论 -
extern 详解
C/C++中extern关键字详解1 基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义。此外extern也可用来进行链接指定。 也就是说extern有两个作用,第一个,当它与"C"一起连用时,如: extern "C" void fun(int a, int b);则告诉编译器在编译fun这转载 2012-11-26 14:16:32 · 358 阅读 · 0 评论 -
map insert 操作
map m_map;m_map.insert(map::value_type("hello",5));m_map.insert(make_pair("hello",5));也就是说,insert后面的数据是pair类型或者是value_type类型了,然而对C++有了解的人都明白,其实value_type和pair 是等价的、insert() 中的参数必须是value_type原创 2012-11-06 14:46:35 · 1096 阅读 · 0 评论 -
find_first_of
int a[5] = { 1,3,4,6,7}; int b[5] = { 1,3,5,7,8}; list roster1(a,a+5); list roster2(b,b+5); int cnt = 0; list::iterator it = roster1.begin(); while( ( it = find_firs原创 2012-11-07 11:44:13 · 316 阅读 · 0 评论 -
istringstream的用法
// map_tranc.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv原创 2012-11-06 16:55:38 · 429 阅读 · 0 评论 -
back_inserter的用法
back_inserter函数式迭代适配器,使用时要包含 iterator头文件。与容器适配器一样,迭代适配器使用一个对象作为实参,并生成一个适应其参数行为的新对象。vector iVec;fill_n( iVec, 10, 0); 在iVec中写入 10 个 元素 ,会报错 ,因为 iVec为Empty.fill_n(back_inserter(iVec),原创 2012-11-07 12:26:58 · 1258 阅读 · 0 评论 -
static 用法
用法一:typedef BOOL (*Func)(int);class A{public: A(Func func):m_pFunc(func){}private: Func m_pFunc;};class B:public A{public: B():A(func){} static BOOL func(in原创 2012-10-28 16:18:33 · 234 阅读 · 0 评论 -
bind -boost
bind - boost头文件: boost/bind.hppbind 是一组重载的函数模板.用来向一个函数(或函数对象)绑定某些参数. bind的返回值是一个函数对象. 它的源文件太长了. 看不下去. 这里只记下它的用法: 9.1 对于普通函数假如有函数 fun() 如下: void fun(int x, int y) { cout }现在我们看转载 2012-10-28 18:52:12 · 262 阅读 · 0 评论 -
const
(1)const 引用可以初始化为不同类型的对象或者初始化为右值。int i =42;const int &r = 42; //去掉const 非法const int &r2 = r+i;原因 :观察将引用绑定到不同的类型时,就可以理解上面的问题double dval = 3.14;const int &ri = dval;编译器原创 2012-10-30 16:39:15 · 264 阅读 · 0 评论 -
支持跨平台
/*Win32*/#if defined(__NT__) || defined(_WIN32) || defined(WIN32) #ifndef WIN32 #define WIN32 #endif #ifndef _WIN32 #define _WIN32 #endif #ifndef __WIN32__原创 2012-10-16 18:05:09 · 1482 阅读 · 0 评论 -
placement new
placement new 是重载operator new的一个标准、全局的版本,它不能被自定义的版本代替(不像普通的operator new和operator delete能够被替换成用户自定义的版本)。在一块已分配的内存创建对象它的原型如下: void *operator new( size_t, void *p ) throw() { return p; }首先我们区分下几转载 2012-07-03 17:35:19 · 449 阅读 · 0 评论 -
C++运算符重载
#include using namespace std;class INT{ // public: friend ostream& operator INT(int i):m_i(i){} INT& operator++() { ++(this->m_i); return *this; } const原创 2012-07-03 12:10:34 · 250 阅读 · 0 评论 -
c++ traits技术
Traits技术可以用来获得一个 类型 的相关信息的。 首先假如有以下一个泛型的迭代器类,其中类型参数 T 为迭代器所指向的类型:template typename T>class myIterator{ ...};当我们使用myIterator时,怎样才能获知它所指向的元素的类型呢?我们可以为这个类加入一个内嵌类型,像这样:template typename转载 2012-07-10 12:03:31 · 240 阅读 · 0 评论 -
non-trivial destructor 和 trivial destructor
trivial理解为无用的,无意义的; non-trivial自然就是有实际意义的如果一个class没有定义destructor,如果这个class中的一个数据成员拥有destructor,那么编译器会自动合成出这个class的destructor来.在这个class的合成的destructor里调用那个数据成员的destructor,这个合成的 class的destructor是有意义的,即转载 2012-07-03 17:19:48 · 743 阅读 · 0 评论 -
char *str 和 char str[]
char *strA1(){ char str1[] = "hello world"; return str1;}char *strA2(){ char* str2= "hello world111"; return str2;}int main(void){ char *ptr1 = strA1();原创 2013-03-25 19:58:31 · 1026 阅读 · 0 评论