#include
using std::cout;
using std::endl;
//定义结构
struct Box{
double length;
double width;
double height;
};
double volume(const Box& aBox);
int main(){
Box box={70.0,60.0,40.0};
d...
分类:
编程语言 时间:
2014-07-11 08:37:11
阅读次数:
189
有关const成员、static成员、const static成员的初始化:
1、const成员:只能在构造函数后的初始化列表中初始化
2、static成员:初始化在类外,且不加static修饰
3、const static成员:类只有唯一一份拷贝,且数值不能改变。因此,可以在类中声明处初始化,也可以像static在类外初始化
#include
using std::cout;
...
分类:
编程语言 时间:
2014-07-11 08:16:29
阅读次数:
299
前些日子,有个同学问我一个关于虚函数的缺省参数问题。他是从某个论坛上看到的,但是自己没想通,便来找我。现在分享一下这个问题。先看一小段代码:
#include
using namespace std;
class A
{
public:
virtual void Fun(int number = 10)
{
cout << "A::Fun ...
分类:
编程语言 时间:
2014-07-10 23:05:08
阅读次数:
297
本设计模式就是简单地记录当前状态,然后利用记录的数据恢复。
比如首先我们有一个类,类需要记录当前状态进行相关的工作的:
class Memo;
class Human
{
public:
string state;
Memo *makeMemo();
void restroDataFromMemo(Memo *m);
void show()
{
cout<<"State: "<...
分类:
其他好文 时间:
2014-07-10 21:58:16
阅读次数:
240
#include
using namespace std;
int main()
{
vectorvec;
for(int i = 0 ;i < 100 ; ++i)
vec.push_back(i);
cout << vec.size() << endl; //100
cout << vec.capacity() << endl; //128...
分类:
其他好文 时间:
2014-07-10 21:17:43
阅读次数:
199
1. 以下三条输出语句分别输出什么?
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
cout
c...
分类:
其他好文 时间:
2014-07-10 20:41:30
阅读次数:
248
今天在写一个判断字符串是否回文时因为短路求值问题导致了一个bug,记录如下:代码如下bool isPal(char str[],int len){ int begin=0; int end=len-1; bool result=true; cout<<str<<endl; ...
分类:
其他好文 时间:
2014-07-09 19:00:02
阅读次数:
216
第一种方法:cout
#include
#include
using namespace std;
int main()
{
double aDouble = 5.141592694827862736487362746374637434343434;
cout<<fixed<<setprecision(20)<<aDouble<<endl;
return 0;
}
第二种方...
分类:
编程语言 时间:
2014-07-08 15:56:26
阅读次数:
208
#include
using namespace std;
int main()
{
// 第一种,使指针不能修改对象的值,注:此时指针可以指向另外的对象
int i = 10;
int j = 100;
const int *pi = &i; // 限定指针无法修改对象的值
//*pi = 1000; // error!
pi = &j;
cout<<*pi<<e...
分类:
其他好文 时间:
2014-07-08 15:45:26
阅读次数:
180
#include
using namespace std;
class A
{
int a;
public:
A(int n):a(n)
{
cout << "Constructor!" << endl;
}
~A()
{
cout << "Destructor!" << endl;
}
};
int main()
{
A a = 10;
return 0;...
分类:
编程语言 时间:
2014-07-08 13:45:04
阅读次数:
184