|
A little further reading on the subject makes it all the more clearer.
It shouldn't be too much hassle to create a CSubject and CObserver containing only the virtual methods I need. Then it's a simple matter of deriving my existing code from these new classes, and have the observers call CSubject::HeyTellMeWhenSomethingChangesWillYa()
Waldermort
|
|
|
|
|
WalderMort wrote: It shouldn't be too much hassle to create a CSubject and CObserver containing only the virtual methods I need.
Nope.
WalderMort wrote: Then it's a simple matter of deriving my existing code from these new classes, and have the observers call CSubject::HeyTellMeWhenSomethingChangesWillYa()
Yes, and now that you strike me as empowered I really suggest you do it this way instead of a lazy shortcut like the one I suggested earlier , because in this case you would create reusable base classes that you can benefit from later. You will also get a clear understanding of the observer design pattern, which will also help you later since the pattern is quite common.
Go 'n get'em boy! Yiee-ha!
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: in this case you would create reusable base classes that you can benefit from later
I have to agree there, it's always useful to create re-usable code and add it to a common folder somewhere. I have got to the point now that I am re-using so much code, that I had to create a single header file just to #include my most used snippets.
As for this Subject Observer pattern. Most of the examples/articles I found simply pass a this pointer back to the observer through a single virtual method. In my eyes this is somewhat over the top, each observer wouldn't know what type of update or even if the update is relevent, but still have to call back to the subject to check what changed.
I took a different approach, much the same as you would normaly use virtual methods. I created a single base class, complete with a list of all virtual calls a class would need. This way the method can be over-ridden directly and whatever updated data is already there.
Infact I may even write an article on it. To think of all those projects where I could have used this, but instead took the far more complicated route of multiple derived types and callbacks...
Again, thanks for introducing this.
Waldermort
|
|
|
|
|
i have put a picture control inside a dialog box and in the picture control i have put a bitmap
Now i want to draw a rectangle(only boundary) inside this bitmap.Further on right side of rectangle i want to put numbers -1 -0.5 0 0.5 1 starting from top to bottom.
Please sugget how can i do this.
Regards
|
|
|
|
|
You can use of CDC::Rectangle function.Is this your question?
|
|
|
|
|
CDC::Rectangle(...) and CDC::DrawText(...)
Russell
|
|
|
|
|
Hi everybody,
i have a class which stores char arrays, for example char name[50];
If i write int test = sizeof(inst->name); test has the value 50, which his OK.
Now i like to send a the char array to a function, there'in it has the form char*
and i sizeof() of this char* returns only the size of the pointer or something like this.
How can i find the number of allocated chars from this char* ?
Big thanks !
|
|
|
|
|
baerten wrote: How can i find the number of allocated chars from this char*
you can use _msize() to find the size of buffer allocated in heap. I.e the function will work in the secnarios like
char *pszName = new char[50];<br />
fun( pszName );
but not for
char szName[50];<br />
fun( szName );
So to solve such pblms we usually pass the size of array also to such functions.
|
|
|
|
|
You should prefer strlen which will check the real size of your null-terminated string and not the size of the 'container'. So, if you copy "Hello" in your buffer, strlen will return 5 and not 50.
Is that what you are looking for ? If no, then you should maybe elaborate a little bit more.
|
|
|
|
|
short answer, you can't. When passing arrays around, it is always good practice to also send the number of items, or use one of the STL templates like std::vector
Waldermort
|
|
|
|
|
Have you not ever used functions that take a buffer and the size of that buffer as arguments?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That's called "array decay" Just google for the term and you'll find the explanation.
|
|
|
|
|
one word (sorta)
std::string myfancystringclass;
|
|
|
|
|
I'm sorry, My english is not well.
I want to display line symbol of GIS in a dialog.My idea is to use listctrl control with owner draw property,I wrote some code , but the result of the program is poor,could anyone give me an idea or some code on how to do it?
|
|
|
|
|
yidingyu wrote: but the result of the program is poor
what you want to draw exactly?
Can some articles (here on CP) on list controls help you?
Russell
|
|
|
|
|
I think it is too difficult for me to explain, because my poor english.
Now,I want to show line symbols in a control(Maybe listctrl control or tree control)Such as Simple line symbol,Cartographic line symbol,Hash line symbol,I use a COM to draw this line,and want to show them in a control.
I try to use listctrl's virtual function drawitem to show these line ,but, I cann't finish the code, could you give me some examples ?
|
|
|
|
|
|
yidingyu wrote: ...but, I cann't finish the code...
Why not? What's the problem?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How would I go about making my application respond to DDE "opens with" functions. I mean when you select "Folder Options" in Explorer and view the action for a file type it has the option to use DDE. I would like to be able to respond to the DDE message for any verb and any file type, like a ShellExecuteHook (Which does not seem to respond to verbs which use DDE).
Could anyone point me in the right direction?
|
|
|
|
|
One way is to "register" your file's extension (i.e., add keys and values to the registry).
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have to input a year so that it will show the month and day of Easter of that year. Professor provided these to calculate it.
[edit]
Than just below, he said: Use individual functions to calculate each of the values
I don't get what he means by that. I can easily use the calculations as an assignment statement, but as a function? Am I understanding him correctly?
-- modified at 5:03 Wednesday 26th September, 2007
|
|
|
|
|
imagine what the forum would become if every of your classmates were asking for help about this homework...
|
|
|
|
|
They are in the class or different classes?;)
|
|
|
|
|
I guess:
int GetEasterDay(int Year){/*Do compute*/}
int GetEasterMonth(int Year){/*Do compute*/}
He wants that you make some homeworks. I think thats really OK
Please read an beginner book about programming like "C++ for Dummies". This give you an overview.
Greetings from Germany
|
|
|
|
|