上一页 1 ··· 3 4 5 6 7 8 9 10 下一页
摘要: 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 阅读(1968) 评论(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 阅读(332) 评论(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 阅读(179) 评论(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 阅读(446) 评论(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 阅读(335) 评论(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 阅读(279) 评论(0) 推荐(0) 编辑
摘要: 1. Java实现interface NetWork{ public abstract void browser();}class Real implements NetWork{ @Override public void browser() { // TODO Auto-generated method stub System.out.println("浏览信息"); }}public class designpattern_proxy implements NetWork{ private NetWork newwork; ... 阅读全文
posted @ 2011-08-29 00:22 wtx 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 0 转自 http://www.cnblogs.com/rollenholt/archive/2011/08/28/2156357.html(1)Java中每个程序至少启动2个线程,一个main线程,一个垃圾回收线程,(2)判断线程是否启动的方法: isAlive()(3) 线程的强制执行: join()(4) 线程的休眠: sleep()Thread.sleep(2000);(5)demo.interrupt();//2s后中断线程(6)demo.setDaemon(true); //后台运行线程(7)h1.setPriority(8);//线程的优先级,优先级的高低与谁 先执行 还不是必然 阅读全文
posted @ 2011-08-29 00:15 wtx 阅读(317) 评论(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 阅读(532) 评论(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 阅读(586) 评论(0) 推荐(1) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 下一页