随笔分类 -  c++

摘要:一、ubuntu下thrift的安装1.下载源代码http://thrift.apache.org/download/下载最新版本thrift-0.8.0.tar.gz2.安装boost库sudo apt-get install libboost-dev libboost-dbg libboost-doc bcp libboost-*3.安装其他相关工具包sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison 阅读全文
posted @ 2012-02-10 14:10 wtx 阅读(13574) 评论(0) 推荐(0) 编辑
摘要:ubuntu下的c/c++环境搭建是比较简单,因为有apt和新立得的帮助.1.首先是配置gcc,在ubuntu安装完成已经有gcc了(gcc是由GNU之父Stallman所开发的linux下的编译器,全称为GNU Compiler Collection, 目前可以编译的语言包括:C, C++, Objective-C, Fortran, Java, and Ada.).但是gcc还不能编译文件.因为缺少一些头文件.那么我们就要来配置这些头文件.在这里我们需要安装build-essential这个软件包,安装了这个包会自动安装上g++,libc6-dev,linux-libc-dev,libst 阅读全文
posted @ 2011-12-03 11:45 wtx 阅读(27687) 评论(0) 推荐(1) 编辑
摘要:js函数集·字符串(String) 1.声明 var myString = new String("Every good boy does fine."); var myString = "Every good boy does fine."; 2.字符串连接 var myString = "Every " + "good boy " + "does fine."; var myString = "Every "; myString += "good bo 阅读全文
posted @ 2011-11-29 21:36 wtx 阅读(326) 评论(0) 推荐(0) 编辑
摘要:1.#include <iostream>using namespace std;int main(){ int i = 0; int j = 0; if(i ++ == ++ j) { cout << "i," << i << "j," << j << endl; } else { cout << "不相等" << endl; cout << "i," << i << "j 阅读全文
posted @ 2011-09-26 21:35 wtx 阅读(384) 评论(0) 推荐(0) 编辑
摘要:1. C++中支持 3中成员函数: static ,非static,和 virtual 函数,两种数据成员,static和非static的2. member的各种调用方式 非static成员函数,在C++中,所有的非 static成员函数都被转化为一个全局的成员函数,并隐式的传给了一个class 的对象的指针,而且选择成员函数的效率与全局函数的效率相同,没有任何负担 虚成员函数的调用, 将会被转化为 一个指针指向vptr,而vptr指向virtual 函数表例如:如果是对 ptr->normalize(),normalize() 是一个 虚成员函数,将会在内部转化为 (*ptr-> 阅读全文
posted @ 2011-09-01 23:43 wtx 阅读(1971) 评论(0) 推荐(0) 编辑
摘要:1. 什么时候能默写出来呢?#include <iostream>using namespace std;struct node{ int data; node *next; node *prior;};class Link{ public: Link() { head_ptr = NULL; tail_ptr = NULL; } void insertNode(); void insertNode(node *ptr); void insertNodeAtHead(node *ptr); void ... 阅读全文
posted @ 2011-09-01 20:59 wtx 阅读(336) 评论(0) 推荐(0) 编辑
摘要:1. C++中有两种数据成员,static 和 非static,以及3种成员函数,static,非static和virtual函数 static数据成员和 非static 成员函数放在class 对象的外面,virtual 函数机制(1) 每个class 产生一堆指向irtual 函数的指针,放在表格中(?) (2) 每一个class 对象被添加一个指针vptr,指向相关的vtable,这个vptr的设定和重置由每一个class的 构造函数,析构函数,和拷贝构造函数自动完成 阅读全文
posted @ 2011-08-31 16:35 wtx 阅读(182) 评论(0) 推荐(0) 编辑
摘要:1. 关于sizeof的运行结果#include <iostream>//在GCC 中using namespace std;class X{};class Y :public X{};class Z : public X{};class W :public Y,public Z{};int main(){ cout << sizeof(X) << endl;//1 cout << sizeof(Y) << endl;//1 cout << sizeof(Z) << endl;//1 cout << 阅读全文
posted @ 2011-08-31 13:41 wtx 阅读(452) 评论(0) 推荐(0) 编辑
摘要:1.#include <iostream>using namespace std;class Foo{ public: Foo(),Foo(int);};//这里被合成的Bar default 构造函数内含有member //object,foo拥有default constructor,所以会初始化Bar::foo()//但是初始化str 的责任是程序员的,即编译器不会初始化str class Bar{ public: Foo foo;//内含 char *str;};void foo_bar(){ Bar bar; }int main(){ ... 阅读全文
posted @ 2011-08-30 21:18 wtx 阅读(344) 评论(0) 推荐(0) 编辑
摘要:1. 由于本例中使用了 boost 的shared_ptr,先看一个shared_ptr:shared_ptr使用的是引用计数方式#include <string>#include <iostream>#include <boost/shared_ptr.hpp>using namespace std;class implementation{ public: ~implementation() { cout << "析构函数" << endl; } void f() { cout << "函 阅读全文
posted @ 2011-08-29 21:19 wtx 阅读(282) 评论(0) 推荐(0) 编辑
摘要:1 当我们以面向对象的观点进入template C ++ 时,继承就表现的和以前不同了C ++ 编译器不进入template base class 观察,解决方式有3种:this->using 声明式明确的支出被调用的函数是属于base类的item 43 的例子#include <iostream>using namespace std;class companyA{ public: void sendCleartext(const string &msg); void sendEncrypted(const string &msg);};void compa 阅读全文
posted @ 2011-08-28 11:33 wtx 阅读(537) 评论(0) 推荐(0) 编辑
摘要:1. n! 当n比较大时,采用数组存放结果#include <iostream>using namespace std;#define MAX 1000//n比较小的时候void n_(int n){ int result = 1; for(int i = 2;i <= n; i ++) result *= i; cout << result << endl;}//函数功能,求n!void f(int n){ int a[MAX]; int p,h;//p 存储当前的结果的位数,h为进位 a[1] = 1; //用来存储运算结果 p = 1... 阅读全文
posted @ 2011-08-25 15:42 wtx 阅读(590) 评论(0) 推荐(1) 编辑
摘要:1. 递归法 #include <iostream>/* 整数划分问题 http://www.cnblogs.com/dolphin0520/archive/2011/04/04/2005098.html*////* f(n, m)= 1; (n=1 or m=1) f(n,m) = f(n, n); (n<m) 1+ f(n, m-1); (n=m) f(n-m,m)+f(n,m-1)... 阅读全文
posted @ 2011-08-25 15:08 wtx 阅读(511) 评论(0) 推荐(0) 编辑
摘要:0 整理自网络1. Java版(转) 要比较的对象必须实现Comparable接口,重写compareTo 方法,Java在红自带有优先级队列的实现PriorityQueueQueue<ToDoItem> q = new PriorityQueue<ToDoItem>();import java.util.Collections;import java.util.PriorityQueue;import java.util.Queue;public class ToDoItem implements Comparable<ToDoItem>{ private 阅读全文
posted @ 2011-08-24 20:06 wtx 阅读(1967) 评论(0) 推荐(0) 编辑
摘要:各种排序算法实现的收集,肯定有你没有见过的。归并,快排,奇偶排,cocktail 排序,梳排序,计数排序,基数排序,LSD基数排序,shell排序,桶排序,鸽巢排序等1. 归并排序的实现#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;void merage(int a[],int low,int mid,int high){ int *temp = (int *)malloc((high - low + 1 阅读全文
posted @ 2011-08-22 21:51 wtx 阅读(664) 评论(0) 推荐(0) 编辑
摘要:1. 100万数据的产生,随机数方式#include <iostream>#include <time.h>#include <assert.h>#include <stdio.h>#include <stdlib.h>using namespace std;const int size = 10000000;int num[size];int main(){ int n; FILE *fp = fopen("data.txt", "w"); assert(fp); for (n = 1; n 阅读全文
posted @ 2011-08-20 21:50 wtx 阅读(2528) 评论(1) 推荐(1) 编辑
摘要:1. 模板模板分类模板和函数模板,其中函数模板是一个通用的函数,其参数类型和返回类型不具体指定,类模板类似,建立一个通用类,其数据成员的类型、成员函数的返回类型和参数类型都不具体指定,用一个虚拟类型来代表。 1 #include <iostream> 2 3 using namespace std; 4 //函数模板 5 template <class T> 6 T cmin(T m,T n) 7 { 8 return ( m<n) ? m : n; 9 }10 int main()11 {12 int n1 = 2;13 int n2 = 10;14 doubl 阅读全文
posted @ 2011-08-20 00:21 wtx 阅读(424) 评论(0) 推荐(0) 编辑
摘要:1 链表#include <stdio.h>#include <malloc.h>typedef struct node{ int data; struct node * lchild; struct node * rchild;}node;void Init(node *t){ t = NULL;}node * Insert(node *t , int key){ if(t == NULL) { node * p; p = (node *)malloc(sizeof(node)); p->data = key; p->lchild = NULL; p-&g 阅读全文
posted @ 2011-08-19 12:04 wtx 阅读(918) 评论(0) 推荐(0) 编辑
摘要:在转自:http://www.cnblogs.com/vongang/ stack//数组实现#include <stdio.h>#include <malloc.h>#define maxsize 10typedef struct{ int data[maxsize]; int top; int base;}seqstack;seqstack * s;void initstack(seqstack * s){ s->top = 0; s->base = 0;}int empty(seqstack * s){ if(s->top == s->ba 阅读全文
posted @ 2011-08-19 11:45 wtx 阅读(873) 评论(0) 推荐(0) 编辑
摘要:前言:前些天问了问了一道题:http://home.cnblogs.com/q/27511/结果网上的评价 都还是理解有点不对,这里记录下我试验的结果以及解决方案1.原题如下:问题是当p离开作用域时,不是应该p变成野指针么,为什么test函数输出依然正确?#include <iostream>using namespace std;class A{ public: virtual void func(){ cout << "A func()" << endl;}};void test(){ A* p; { A a; p = &a; 阅读全文
posted @ 2011-08-17 22:20 wtx 阅读(3576) 评论(7) 推荐(3) 编辑

点击右上角即可分享
微信分享提示