|
<br />
TestInt(int newValue) <br />
{ <br />
TestInt();<br />
_value = newValue; <br />
}<br />
Should be
<br />
TestInt(int newValue) <br />
: _value(0)<br />
{ <br />
_value = newValue; <br />
} <br />
C++ doesn't support the notion of 'delegating constructors', I'm guessing you're familiar with java. In C++ you have to initialise all the members that need to be initialised in each constructor. A good artical on this topic was published in a recent C/C++ users journal
Delegating Constructors? (by Herb Sutter &Jim Hyslop),
C/C++ Users Journal, 21(5), May 2003.
|
|
|
|
|
I've changed the code as you've said but sadly it still doesn't work. I'm using VC++ 7, does it help saying that?
And here is the copy+paste from the output after the changes:
i is 0, t is 50, x is 2081702084, y is 88
i is 50, t is 100, x is 2081702084, y is 88
I think the problem is somewhere how the printf function call handles the class value, but in some vars the value is right, on other vars the value is completely absurd.
Anyone could help in the solution?
Thanks,
Rui
is this a sig?
|
|
|
|
|
Sorry, my fault, didn't read it closly enough. printf uses va_args, and the conversion operator may not be called.
You have two choices:
1/ explicitly extract the int you want
2/ use standard output stream, they have to use your conversion operator, because they have no other choice.
cout << "i is " << i << " t is " << t << " x is " << x << " y is " << y << endl;
Instead of using printf
|
|
|
|
|
Thanks, it works
Isn't there a way to enforce printf using the conversion operator, not using explicit extraction?
Thanks again,
Rui
is this a sig?
|
|
|
|
|
There is, but using standard output streams is much better practice in c++, it allows you to be far more flexible and typesafe. If you insist on using printf you could try:
1/ changing the conversion operator to a getValue method.
2/ put an explicit cast within the printf statement.
|
|
|
|
|
How do you declare the variables and associate them with my controls using class wizard? I have set up all my controls but when I look in the members variables tab, it's empty. Do I need to do something else?
|
|
|
|
|
Right-click on the control and select add variable. Here is an example of a button.
DDX_Control(pDX, IDC_BUTTONX, m_BtnX);
Kuphryn
|
|
|
|
|
I did right-click and nothing that mentions variable comes up in the list. Did I mentioned that I have c++ 6.0? I wish I could show you a picture of what I'm doing but I don't know how to upload here plus I'm not a member. Maybe I can post it on my site and link it? If you need it.
|
|
|
|
|
There are three basic components of any control. First is the member variable declaration. This defines a member variable of the type of your control. Second is the data distribution that occurs between your control and the member variable (as mentioned above). Third is message mapping. Controls fire messages to your application whenever certain things occur (i.e. u click the mouse, etc...) When you want to do something on these events, you are "handling" the messagess. Apart from threading, this is the heart of your application.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Hi,
I have two class in wich I put member function. I want to pass a pointer to member function from one class to another class member function. I utilize Visual C++ 6.0 and MFC.
Here's the class definition:
class A {
...
public:
void TestA ( int x);
...
};
class B {
...
public:
void TestB( void(*ptr) ( int ));
...
};
Here's is the member function A::TestA ( int x) from wich I want to pass a pointer to the member function B:: TestB( void(*ptr) ( int )).
void A::TestA ( int x)
{
// Definition of the pointer to member function
void (A::*pt) ( int );
// Assignment
pt = &A::TestA;
// Now, I want to pass the member function A::TestA ( int x) address to the member function TestB of class B:
B objB;
objB.TestB ( pt );
}
This is not compiling in Visual C++.
I get a compile error who explain that the calling convention __cdecl does not correspond.
I have read many web site about this subject. Unfortunately I am not able to get the right code to correct my error.
I have read about callback and functor, but I can't understand.
Do you have any help ?
Thanks,
Claude Gagnon
|
|
|
|
|
A pointer to a member function is not interchangeable with a pointer to a global function, because the former also has a this pointer. You can see it in the code, void(*)(int) versus void(A::*)(int)
One way to fix it is to have TestB() declared as void TestB( void(A::*ptr) ( int )) although without knowing what your whole app is like I don't know if this the best way.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
How can we enter an integer data in a database?
My database is SQL
When I try to do this I see an error
rose:
|
|
|
|
|
Hello,
how can I load a gif file into the display
device context? I don't want to use a resource.
Thanks
|
|
|
|
|
How about GDI+?
Regards,
BB
|
|
|
|
|
LoadImage(AfxGetInstanceHandle( ),
strFileName,
IMAGE_BITMAP,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_LOADFROMFILE);
Swimming in a fish bowl
|
|
|
|
|
Hi all code gurus,
I'm trying to get all the windows that have a task bar button, I use EnumWindows() to enumerate thourgh all the windows but cannot figure out whether a given window has a task bar button. Any ideas how to accomplish this?
Regards
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
Use GetWindowLongPtr API function with GWL_EXSTYLE to retrieve the extended window style for each window, then check for the WS_EX_APPWINDOW bit in this value. If it's set, then the window is visible in the taskbar.
|
|
|
|
|
|
Well, actually that didn't work, when I do this I get only a few windows, I assume it only returns windows of applications with only one running instance, when there are multiple instances on an applicaion no windows for that application are returned .. thanks anyway
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
I don't think I exactly did catch what you mean with "windows with a taskbar button" but did you try the Spy++ utility? Just run spy++ and right click/properties on any window, there you can see which styles it has, what parent window it belongs to and lots of other stuff which I think could be helpful to further investigate your problem and maybe find a general solution for those windows you want to differentiate from the others. Hope this helps..
|
|
|
|
|
What is the easiest way to convert a CString to WSTR in MFC under non unicode builds?
John
|
|
|
|
|
Answering my own question.
<br />
USES_CONVERSION;<br />
<br />
serverInfo.pwszName = T2W((LPTSTR)(LPCSTR)strServer);
|
|
|
|
|
|
Mike Thanks. I checked out the link before I asked the question but did not directly find the answer there. Maybe I did not look hard enough there are a lot of examples in the article.
John
|
|
|
|
|
Actually,
T2CW(strServer)
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|