|
For values greater than 0, the sum of all integers between 1 and n can be computed as n(n+1)/2.
Now for your specific problem, we want to compute the sum of all integers between x and y. This can also be expressed as the sum of all integers between 1 and y minus the sum of all integers between 1 and (x-1). So the final answer would be...
result = y(y+1)/2 - (x-1)x/2
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Finding the sum of the numbers between two integers can be done as follows:
int i = x + 1; // we start counting 1 higher then x
// or make this i = x if you want to include x
int sum = 0;
while (i < y) { // repeat while we haven't reached y
// or make this i<=y if you want to include y
sum = sum + i;
i++;
}
voila.
or shorter:
int sum = 0;
for (int i=x+1;i
|
|
|
|
|
I have the following class:
class BaseClass {<br />
static char* wp;<br />
<br />
void Dynamic(char* s) {<br />
this->wp = s;<br />
}<br />
}
and a derivative:
class Derived : public BaseClass {<br />
}
Basically, what I want to accomplish is this: I want to reference the static member wp of the derived class in the inhereted function and reference the BaseClass member in the Baseclass function
so..
BaseClass *bc = new BaseClass();<br />
Derived *d = new Derived();<br />
<br />
bc->Dynamic("something");<br />
d->Dynamic("something else");
After this code, I want bc::wp != d::wp, but alas, bc::wp == d::wp == "something else". I would LIKE to have bc::wp == "something" and d::wp == "something else".
Anybody have any clues as to how I might realise this? And yes I do realise I could make them non-static, but I am interested in a way of doing this... if at all possible.
|
|
|
|
|
If you want the derived class to have its own, separate copy of the static member,
you have to declare it in the derived class. Then, you also have to implement Dynamic() in the derived class so it refers to the derived class' static member and not the base class' static member.
|
|
|
|
|
Can I create a CWnd* class from an DLL that is loaded at runtime and the use it.
Like this.
I have a tabview in my program that takes CWnd* objects.
And say that the user select something and then a DLL is lunched ( a plugin )
And all Plugin DLLs have a function call CreateObject(). It calls it and returns a CWnd* object.
The main program don’t know anything about the object except that it’s a CWnd* object
Now.
Can I just take this object and threat it as any other object ?
What restriction are they?
Do I need to do some special stuff to make it work?
What I understand is that I need to let the DLL also take care of
the deleting of the object, since it create it. Is that correct ?
/Mathias
|
|
|
|
|
I have a object that I created that is derived from CWnd. In my SDI
application with a CFormView, I have created the object. (Draws a box on the
form) Now I would like the object to handle the left mouse down event. I
added the left mouse button down event to my object. But how do I ??? so
that my object receives the left mouse down event when a user clicks on the
object? (box)
Thanks
|
|
|
|
|
MFC sure can be confusing.........
When would you use OnPaint() instead of OnDraw() for drawing in an MFC application?
Should on be used in a dialog and the other used in a doc/view app?
|
|
|
|
|
Well, OnPaint() calls OnDraw() . I think OnDraw() is specific to views, whereas OnPaint() is for repainting in general.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I want to change the background color of the Combo box with drop down style.
I tried doing it using WM_CTLCOLOR message code. however it works for all edit boxes and combo boxes of style list box and not for the drop down.
kindly advise on this.
|
|
|
|
|
How i can convert a CString to LPCTSTR?
I can't found an easy solution for this. Please give a help.
Thank's bros.
|
|
|
|
|
Nothing easier than that:
CString cstr;<br />
LPCTSTR lpString = (LPCTSTR)cstr;
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
No need to cast:
LPCTSTR lpString = cstr;
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
You don't need to convert anything, CString has an implicit LPCTSTR cast. If a function takes a const char* as parameter, simply take your CString.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
For unicode you better use the following
CString cstr;<br />
char * myString = (char *) (LPCTSTR) (cstr);
|
|
|
|
|
|
|
That is so wrong in so many ways.
First off, if it is a UNICODE build, then you will end up with a pointer to data such as.
0x65 0x00 0x66 0x00 0x97 0x00
To convert from a T string to a const char string, use the following macro:
T2CA (temp)
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
This is just wrong, whether UNICODE is used or not. If you need me to explain, let me know. Now it's quittin' time!
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
NO. Simply casting an LPCTSTR to a char * simply converts the pointer, not the characters. You must convert the characters, which requires using something like WideCharToMultiByte .
Software Zen: delete this;
|
|
|
|
|
XP saves all settings in binary files
located in windows\\system32\\config right?
i looking for some way to read these files?
i want to access registry from another os
|
|
|
|
|
If the other OS is Windows-based, you can use RegConnectRegistry() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
It is linux. so i need some code to do id
without windows API
|
|
|
|
|
Well, I don't know the format of any of the files that comprise the registry, so you may have a bit of work ahead of you.
Good luck.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Have you considered Winelib[^]? It may provide the Win32 functions you're looking for.
Otherwise, you might need to make your own limited version of the Remote Registry service to run on the Windows box.
- Mike
|
|
|
|
|