|
You said :
"
_ I debugged your modified code and found as you said, MyFnc() was called before Test(). But if MyFnc() was called first, I expected that the result must be "123" but it was still "321". Because when MyFnc() is called, the return value is 1 and 2 calls of Test() later returns 2 and 3."
The command before exec is : cout << a.Test() << a.Test() << a.Test() << endln ;
in Step 1 command is equivalent --> cout << a.Test() << a.Test() << "1" << endln ;
in next step command is equivalent ---> cout << a.Test() << "2" << "1" << endln ;
and in last step is ---> cout << "3" << "2" << "1" << endln ;
Now why you expect you see "123" in output . It is reasonable you see "123" in output .
|
|
|
|
|
if you add endl at the end of each a.Test(),you will get the right result:123
it's really strange!
|
|
|
|
|
First note that the problem has nothing to do with "cout":
----------------------------------------------------------
//#include <iostream>
//using namespace std;
#include <stdio.h>
class A
{
private:
unsigned int m_nCount;
public:
A()
{
m_nCount = 0;
}
~A(){}
int Test(char ch)
{
// cout << ch << endl;
printf("%c\n", ch);
m_nCount++;
return m_nCount;
}
};
void main()
{
A a;
printf("%d%d%d\n", a.Test('a'), a.Test('b'), a.Test('c'));
// cout << a.Test('a') << a.Test('b') << a.Test('c') << endl;
}
----------------------------------------------------------
Output is:
c
b
a
321
The same output is produced if "cout" is used. Note the "a", "b" and "c"s - this shows what's happening: The expressions are being evaluated from right to left.
There is nothing going wrong, see here:
http://www.kuzbass.ru/docs/isocpp/expr.html
Here's a quote:
"-4- Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified."
Steve
|
|
|
|
|
_ OK, I think that I have something misunderstood in my mind. I used to think that cout evaluates from the left to right but it turns out it doesn't. Thanks everybody for help
|
|
|
|
|
Don't do that. When you put multiple side-effects in the same function call (operator<< is just a function call, after all) you're getting into compiler-specific behavior.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hello, everyone !
I encounter a problem. When I set the VC++ (7.0) "Optimization: Maximize Speed(O2)", my program can't work correctly. But when I changed the Optimization to other, for example to "Minimize Size (O1)" or disable, my program can
work correctly.
But for some reason, I must use the (O2) option.
I want to know by which way , can I find the bug in source ?
Thanks a lot!
Best Regards,
|
|
|
|
|
Hello guys.
I'm sorry. I'm not sure I'm in right board section.
I tried to search what I'm going to ask. but failed..
I’m going to develop a dynamic library over several platforms; they are Windows, Mac and Linux.
I expect the forms of output would be ‘.dll’ , ‘ .dylib’ and ‘ .so” .
They must be built from same source codes.
But unfortunately I have neither Macintosh nor Linux machine.
So I have to build that all kinds of libraries in Windows XP system.
And I know it is very difficult to build an application for Macintosh using the Windows system. (and vice versa)
But what I'm trying to do is for just 'dynamic library' using ANSI C.
I think the cross-compiling for 'library' is easier than for 'applications'.
am I right?
And one of what I've found is 'gcc'of MinGW.
I'm wondering if it is really possible to build the three kinds of output of dynamic library from same source code using gcc of MinGW?
If not , how can I do that??
Thanks~
-- modified at 1:04 Saturday 22nd July, 2006
|
|
|
|
|
How to forbid the user to terminate my program.(in taskmgr).
Can I accomplish that to promote the process privilege.Thanks for your help.
|
|
|
|
|
Why would you want to do that? Are you writing malicious applications?
If you're writing a normal application, make it so good that no-one would want to exit it.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
You can't. This is by design of windows.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
If its an important application that needs to be running 365 days of the year, it should be firstly be running on a dedicated server. The less user interaction the more chance it wont be closed by accident. You can then start by overridding the usual suspects: OnClose, OnOK, OnCancel. Although as previous replies have said, a user could still terminate the application via task manager. - Maybe writing the application as a desktop application is the wrong avenue to take in this instance and writing the program as a windows service would be more fitting. However, even though this would give you some benefits ( e.g from people logging onto the machine and mistakingly terminating the program ) you can still not guarantee that your program could not be stopped.
If you really want to make sure that this application is not closed, you could write a heartbeat/pulse utility which periodically checks to make sure that your app is still running, and if its not re-start it! - then ofcourse some of the emphasis then shifts to the heartbeat/utility app. If this gets closed, then your back to step 1. - You could make the same heartbeat/pulse app distributed, in that it could be present on multiple servers, with all of them checking in with the server your 'important' app is running on.
Just a few ramblings.
|
|
|
|
|
you can create another process to monitor the main process, once the main process had been terminated, the other process create it immediately. and also the main process monitor the other process to keep it running.once it has been terminated create it immediately.
i think this method may satisfy your needs.
|
|
|
|
|
If this was easy to do every virus/trojan writer would be doing so already.
Steve
|
|
|
|
|
A good answer
|
|
|
|
|
Hook the terminate process API in kernel32.dll. Then when user right-click on the process list of Task Manager to kill process (tree), it takes no action.
Maxwell Chen
|
|
|
|
|
Hi fellows,
Does anybody here knows how can I change the color of a selected text within a Textbox? I'm using MFC's CEdit.
Any comment will be really appreciated. Thanks in advance.
Regards,
FG.
A polar bear is a bear whose coordinates has been changed in terms of sine and cosine.
|
|
|
|
|
Do you mean you want to change the color of the highlight that shows what text is selected, or do you mean you want to select text, and then change its color?
I don't think that the basic Edit control is capable of multi-colored text. I think you need something more advanced like the RichEdit Control.
|
|
|
|
|
In general, for a specific control, it is not possible. However you can change the selection-highlight colour for just your application by hooking the GetSysColor API and returning your custom colour.
www.catch22.net/tuts/tips2.asp[^]
|
|
|
|
|
|
Hello,
I am attempting this example
http://www.codeproject.com/managedcpp/ijw_unmanaged.asp[^]
I am newbie so let me clear myself what i understood and where I got stuck.
This solution contains three project
1) C # Class Library
2) C++ Managed Library
3) C++ Unmanged Console Application
Am I correct? If so
Q. after Building 1) and 2) I get two .dlls. In this example's case they are ManagedClasses.dll and ManagedWrapper.dll. HOWEVER to build 3) I need four items, the above two .dll files, IManagedWrapper.h file AND ManagedWrapper.lib file. CAN SOMEONE PLEASE TELL ME HOW TO MAKE .lib file out of 2) ?
Q. another question i have is about how to make this projects? I mean When I create a C # library project in .NET 2005 it won't let me include System.Windows.Forms. The included Project sample with the link above somehow gets around it. Can someone explain me how? Also How is 2) (C++ Managed Library ) created? in .Net? when I tried making one.. I ended up with six default files. Do i just delete them?
Thx a lot
Sameep
|
|
|
|
|
First, you should understand rhe idea: you are tring to run unmanaged code in the manged framework. Thus, the MangedWrapper is an adaptor between the codes which by one side obeys the rules of the managed framework but is capable wrap the unmanaged code and make it managed too. So, the managed apllication calls the wrapper which calls the unmanaged code. In other words the managed code should "know" the Wrapper and the Wrapper should know the "unmanaged" and not the other direction. When you want to extend the managed appliction and to intorduce new classes you should insert the refference to the assembly (or dll in other words)in the project of the mannged application. On the other hnd the wrapper includes the h file of the unmanaged class.
2) When you create a new project choose Visula C++ project category and then Managed C++ class
I hope this helps you
DavidR
|
|
|
|
|
How do I get GetPrivateProfileSectionName function to work in VC++.NET 2002? It works fine in the 2003 version, but I can't get it to work in the 2002 version which is what I use at home. The error is that it is an undeclared identifier. I am assuming I need to include some header file, but I don't know which one though I did see some references to a kernel32.dll. How do I import this dll or have the compilier link it when it is compiled?
Roj
-- modified at 16:32 Friday 21st July, 2006
|
|
|
|
|
Look up the function name in the MSDN library, and down at the bottom of the page it tells you exactly what header file to include, and what library file to link with.
|
|
|
|
|
Yes, I know and I tried that, but it still comes up with the same error. It says that it requires kernel32.lib that is declared in windows.h. So, I included the windows.h and I added the kernel32.lib to the linker object/library modules, but still it fails to compile and always says undeclared identifier.
Roj
-- modified at 1:30 Saturday 22nd July, 2006
|
|
|
|
|
Ok, I got it to work, but I had to move the kernel32.lib from its normal directory into the directory where my project is. I must need to set the path somewhere.
Roj
-- modified at 1:29 Saturday 22nd July, 2006
|
|
|
|