Friday, September 23, 2011

my public key at mit

generate your key
and then export your public key in ascii format
put it on the keyserver pgp.mit.edu
now, you could simply type the line below to get the public key

gpg --keyserver pgp.mit.edu --recv-key 57FC306D

it is awsome.

next time you write message to me, remember to encrypt it first using my public key.

Friday, September 16, 2011

chapter11

ERROR:default argument given for parameter...
You should know that you could only make default value for parameter in the definition not on the implementation. Just take it out from your cpp file, only have it on header file.

ERROR:assignment of data-member ‘Time::hours’ in read-only structure
Time sum(Time& time) const
{
time->hours = time.hours + time->hours;
...
}
显然这里出错是因为sum function是const的,试图改变这个this,不对
可改为
Time sum(Time& time) const
{
Time sum;
sum.hours = XXX;
sum.minutes =XXX;
return sum;
}

ERROR: redefinition of Time() function
constructor could be initialized in the header file, then you don't need to have it in the cpp implementation file.

ERROR: no match for operator+
note that there should be a space between operator and op, like: operator +
Time operator +(const Time& time) const;

ERROR: no match for operator *
Remember, the left operand is the invoking object. If you overload * in class Time, you need to make Time object on the left side, like this:
time1 = time1 * 1.5; because it could be translated into: time1 = time1.operator *(1.5);
not: time1 = 1.5 * time1; it cannot correspond to a member function, 1.5.operator *(Time &time)????
Could use non-member function!@!!

Question1:
I made ----- Time sum(const Time& time) const ---, how come I still can use time1=time1+time? It has changed time1. but aren't we supposed to make time1 const, that is the second const for, right?

Thursday, September 15, 2011

Assignment2

ScopedArray:

use 'class' or 'typename' for template parameter
They are equivalent after all.

an error:
cannot convert 'this' pointer from 'const ScopedArray' to 'ScopedArray &
how to solve it:
make the function in class 'const'

an error
error C2440: 'initializing' : cannot convert from 'const ScopedArray' to 'bool'

conversion operator
chapter11 p548

const, if you have const object, your operator should also be const

Thursday, September 8, 2011

Tuesday, September 6, 2011

381 byzantine generals problem

http://blog.csdn.net/turingbook/article/details/3946421
所有程序员需要读的

分布式理论, Byzantine generals problem





compute Erdos numbers with OO design

Wiki page about Erdos number:
collaborative distance based on authorship of mathematical papers

google groups post talking about this:
using BFS to search the collaborative distance from the author to Erdos, which is a undirected graph.

contest on such problem
create BFS at first and then search each author

百度文库
BFS ppt, with some pseudo code here

somebody implement it us C language

c++ implement here:

this one is better, much like OO design here

``````````````````````````````
First, try to use "shortest path faster algorithm" (SPFA)

second, use "Breadth first searching" (BFS) algorithm.


Friday, September 2, 2011

memory leak valgrind

test the program to see if it has memory leak inside.

install a program: sudo apt-get install valgrind
reference:


Thursday, September 1, 2011

fancy stuff for vi

in vi, the default indent is 8, while in visual studio, it is 8, so how to change it to 4 from 8.
check out this website:

in vi:
:set tabstop=4

or change the file ~/.vimrc

I put set nu in the end of file, and now it will automatically show the line number.

Tuesday, August 23, 2011

Blog Introduction

This blog is for my course study 2011 fall.

CS251 Software Intermediate Design
CS381 Advanced Operating System
CS395 Special Topics Dr. Yi Cui