Design Pattern Group

San Diego Design Pattern Group hosted by Chester, Gene, Xin and Danny

Monday, July 30, 2007

Constructor missing while writing class to use in std::map (c++)

I meant to implement a two dimensional hash map using std::map with c++ STL.
First of all, a data class was defined.

class DInfo {
public:
int i, j, k;
DInfo(int _i, int _j, int _k) { i=_i; j=_j; k=_k; }
};

Simple, enough. Now, it's time to define a two dimensional hashmap.

typedef std::map DMAP;
std::map diMap;

No problem is observed till here. Let's write some codes to use them.
There're some RogueWave stuff starting with "RW" for DB interface but just ignore that part.

RWDBTable tbl=database.table("MyTable");
RWDBSelector sel=database.selector();
sel << tbl["Field1"] << tbl["Field2"] << tbl["Field3"];
RWDBReader rdr = sel.reader(conn);
while (rdr()) {
int i, j;
rdr >> i >> j;
DMAP dmap=diMap[i];
DInfo di(i, j, k);
dmap[j]=di;
diMap[i]=dmap;
}

Everything looks fine. Let's compile it using gcc. Ooops!

testSDDI.cpp:48: error: no matching function for call to `DInfo::DInfo()'
DInfo.h:4: note: candidates are: DInfo::DInfo(const DInfo&)
DInfo.h:13: note: DInfo::DInfo(int, int, int)

Huh!!!??? What happens here?
I spent couple of hours to find out the problem of my code and found, finally.
It's missing default constructor of the class DInfo. Let's add the default constructor.

class DInfo {
public:
int i, j, k;
DInfo(int _i, int _j, int _k) { i=_i; j=_j; k=_k; }
DInfo() { i=j=k=0; };
};

In the following line above

...
dmap[j]=di;
...

The default constructor of DInfo is called to instantiate an object for the element of dmap[j] seemlessly
and it calls copy constructor to copy(overwrite) it the contents of di.
Thus we still need default constructor although no actual code calls it.

Now, it's compiled smoothly. Yahoo!

Remember, we'd better implement a default constructor for a class while we're using some library
without knowing the detail of it.

1 Comments:

Anonymous Anonymous said...

buy ativan ativan overdose long term effects - long until ativan withdrawal

1:31 AM  

Post a Comment

<< Home

Thursday, March 30, 2006

Flyweight

With a little help from dictionary.com, it is shown that a flyweight has little to do with a fly wheel...

fly·weight

n.
    1. A weight division in professional boxing having an upper limit of 112 pounds (50.4 kilograms), between junior flyweight and junior bantamweight.
    2. A boxer competing in this weight division.
    3. A similar weight division in other sports, such as weightlifting.
    4. A contestant in this weight division.
  1. Something that is particularly small, light, or inconsequential.

1 Comments:

Blogger Chester Kim said...

That is nice definition.
Thanks.

1:36 PM  

Post a Comment

<< Home

Thursday, February 02, 2006

Free on-line book abut design pattern

There's a free online book: The Design Pattern Java Companion
Check it out!

Chester

0 Comments:

Post a Comment

<< Home

HFDP in Smalltalk

I found a Korean page studying HFDP(Head First Design Pattern) in Smalltalk.
It would be interesting for you all, too.
Look at it.

HFDP in Smalltalk - Chap 1. Duck and Subclasses
HFDP in Smalltalk - Chap 1. Classes implement Flybehavior Protocol
HFDP in Smalltalk - Chap 1. Classes implement Quakbehavior Protocol
HFDP in Smalltalk - Chap 1. Test codes and Duck caller
HFDP in Smalltalk - Chap 2. WeatherData Class (Direct implementation of Observer)
HFDP in Smalltalk - Chap 2. DisplayElement Class (Direct implementation of Observer)
HFDP in Smalltalk - Chap 2. Subclasses of DisplayElement
HFDP in Smalltalk - Chap 2. WeatherStation Class
HFDP in Smalltalk - Chap 2. WeatherData Class (using dependency)
HFDP in Smalltalk - Chap 2. DisplayElement Class (using dependency)
HFDP in Smalltalk - Chap 2. WeatherData (using event)
HFDP in Smalltalk - Chap 2. DisplayElement and subclasses (using event)
HFDP in Smalltalk - Chap 2. Graphics example in Smalltalk
HFDP in Smalltalk - Chap 3. Beverage and subclasses (without condiment)
HFDP in Smalltalk - Chap 3. CondimentDecorator and subclasses
HFDP in Smalltalk - Chap 3. Test code (starbuzz coffee)
HFDP in Smalltalk - Chap 3. Refactoring Condiment class

Have fun! (Study Korean, too ^^)

0 Comments:

Post a Comment

<< Home

Wednesday, February 01, 2006

Assignment at work

Hi Guys,

I got an interesting assignment yesterday.

We have running log of our main application stored in database within complex db tables (prescription log). Couple of major insurance companies require us to report them our prescription history to use their formulary information. The problem begins with all the different message formats of reporting and all the reports are based on the running log database with certain date range. Running log table has a time stamp field.

Let's think about this. It obviously contains one part "stays as same" and the other part "varies".
Isn't it good challenge for using design pattern?

I don't have any clear idea about this little project but I believe you guys can help me with this.
Any comments and ideas are welcome!

Chester

0 Comments:

Post a Comment

<< Home

Friday, January 20, 2006

Presentation Schedule

We've met last night and had great discussion about Strategy & Observer patterns.
(Thanks Xin & myself ^^, all others!!)
Now, we have full schedule. Keep in mind.

1/19
Chester - Intro to Design Pattern (Strategy Pattern)
Xin - Observer Pattern

1/26
Eugene - Decorator Pattern
Jin Sun - Factory Pattern

2/2
Danny - Singleton Pattern
Chester - Command Pattern

2/9
Xin - Adapter and Facade Patterns
Eugene - Template Method

2/16
Intermission - Discussion about the first half of design patterns

2/23
Jin Sun - Iterator and Composite Patterns
Danny - State Pattern

3/2
Chester - Proxy Pattern
Xin - Compound Patterns

3/9
Eugene - Better Living with Patterns
Jin Sun - Leftover Patterns I

3/16
Danny - Better Living with Patterns
Irene - Leftover Patterns II

Chester--;;

0 Comments:

Post a Comment

<< Home

Monday, January 16, 2006

Meeting on this thursday

As you guys know, our sunday meeting has been postponed to this thursday night.
I announce it again.

When: 7pm, 1/19 (Thursday)
Where: Chester's place
What: Chap. 1. Intro to Design Patterns - presented by Chester
Chap. 2. the Observer Pattern - presented by Xin

See you guys!

Cheers!

Chester (Gyu-Man) Kim

<-- This is our text book. Prepare it! (check out amazon)

0 Comments:

Post a Comment

<< Home

Design Pattern Study Group

We're design pattern study group in San Diego.
Our initial members are Chester, Eugene, Xin, Danny, Jinsun and Irene.
We'll discuss about design pattern (a software pattern approach for object oriented design) with the book 'Head First Design Pattern'.

Cheers!

2 Comments:

Blogger Xin the Great said...

Xin the Greate say hello to our geniuses.

12:09 PM  
Blogger Chester Kim said...

Welcome guys!

2:49 PM  

Post a Comment

<< Home