- 浏览: 63402 次
- 性别:
- 来自: 珠海
最新评论
-
IceWee:
谢谢,明白了一点点,初学者我是。
把类的析构函数写成虚函数的用意
文章列表
C/C++格式化字符串说明 C++的格式化字符串经常用作格式化数字的输出、字符串合并和转换等等很多场合。
1. 格式化规定符
━━━━━━━━━━━━━━━━━━━━━━━━━━
符号 ...
- 2009-10-11 14:59
- 浏览 2871
- 评论(0)
这是在林锐的《高质量程序设计指南》中看到的,特此记录下。
1. plain new 普通new
void*operator new(std::size_t)throw(std::bad_alloc);
void operator delete( void *) throw();
该运算符在分配失败时将抛出异常,而非返回NULL。使用时要包含 <new>头文件。正常使用new,但要配以异常处理。如:
char *getMemory(unsigned long size)
{ char * p = new char[size];
retur ...
- 2009-08-13 15:11
- 浏览 3155
- 评论(0)
注意:共8题,答题时间为2.5小时;程序题请说明解题思路,这个非常重要。
一、在C语言的for循环中,break和continue有什么区别。
二、请列举三种你最熟悉的排序算法,并说明它们的时间复杂度是多少。
三、请用位移和加法改写表示式:a * 36;
四、有如下一棵二叉树,请写出它的前序遍历、中序遍历和后续遍历的结果。
A
- 2009-08-11 16:29
- 浏览 1569
- 评论(0)
typedef int (*pfun)(int x,int y);解析:这里的pfun是一个使用typedef自定义数据类型。它表示一个函数指针,其参数有两个,都是int类型,返回值也是int类型。可以按如下步骤使用:1 typedef int (*pfun)(int x,int y);2 int fun(int x, int y);3 pfun p = fun;4 int ret = p(2, 3);简单说明:q 第1行定义了pfun类型,表示一个函数指针类型。q 第2行定义了一个函数。q 第3行定义了一个pfun类型 ...
- 2009-08-11 15:47
- 浏览 1461
- 评论(0)
#include <iostream.h>
#include <stdlib.h>
void main()
{
int a;
char data[30];
cout <<"Enter a Dec number:" <<endl;
cin>>a;
itoa(a,data,14);
cout <<"Fourteen:" <<data <<endl;
}
只要将itoa的第三个参数改为想要转换的进制数就 ...
- 2009-08-09 21:05
- 浏览 745
- 评论(0)
不用临时变量也可以交换变量的值
- 博客分类:
- 算法
方法一:
void swap(int *p, int *q)
{
*p = *p + *q;
*q = *p - *q;
*p = *p - *q;
}
方法二:
#include <stdio.h>
int main(int argc, char *argv[])
{
int a = 2, b = 6;
a = a ^ b;
b = b ^ a;
a = a ^ b;
printf("a = %d b = %d\n", a, b);
...
把类的析构函数写成虚函数的用意
- 博客分类:
- vc++
#include <iostream.h>
class Base
{
public:
Base() { mPtr = new int; }
~Base() { delete mPtr; cout<<"Base::Destruction"<<endl;}
private:
int* mPtr;
} ;
class Derived : public Base
{
public:
Derived() { mDerived = new long; }
~Derived() { dele ...
- 2009-08-09 20:23
- 浏览 3700
- 评论(1)
1.Oracle数据库
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:orcle";
String user = "test";
String password = "test";
Connection conn = DriverManager.getConnection(url, user, password);
2.DB2数 ...
- 2009-08-06 21:27
- 浏览 1273
- 评论(0)
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
public class TestSuspend{
public static void main(String[] args){
JFrame jf = new JFra ...
- 2009-08-05 22:10
- 浏览 3921
- 评论(0)
/// <summary>
/// 将指定字符串按指定长度进行剪切,
/// </summary>
/// <param name= "oldStr "> 需要截断的字符串 </param>
/// <param name= "maxLength "> 字符串的最大长度 </param>
/// <param name= "endWith "> 超过长度的后 ...
- 2009-06-15 16:49
- 浏览 771
- 评论(0)
最后运行的效果图:
HTML的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/ja ...
- 2009-06-15 16:30
- 浏览 687
- 评论(0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DAL
{
public class SQLHelper
{
private SqlConnection conn = null;
private SqlCommand cmd ...
- 2009-06-02 18:00
- 浏览 1093
- 评论(0)
#include<iostream.h>
struct T {
int w;
union T2 { char c; int i; double d; } U;
};
int main()
{
cout<<sizeof(int)<<", "<<sizeof(double)<<endl;
cout<<sizeof(T)<<endl;
return 0;
}
缺省的大部分是以“自然对齐要求最严格”的数据的“自然对齐要求”,可以用
#pragma pac ...
- 2009-05-22 22:37
- 浏览 835
- 评论(0)
1、DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年=currentTime.Year; 1.3 取当前月 int 月=currentTime.Month; 1.4 取当前日 int 日=currentTime.Day; 1.5 取当前时 int 时=currentTime.Hour; 1.6 取当前分 int 分=currentTime.Minute; 1.7 取当前秒 int 秒=curren ...
- 2009-05-14 18:53
- 浏览 876
- 评论(0)