|
Allad wrote: Visual Studio 2005 compiler has been made more ISO compliant so it no longer accepts implicit int declaration.
So why don't you go ahead and fix it? Why leave bad code in your source?
|
|
|
|
|
Nishant Sivakumar wrote: So why don't you go ahead and fix it? Why leave bad code in your source?
In my project I'm using a library with thousands of code lines. And the real problem is that library. I don't dare mess with such a huge amount of code I've not written myself.
Anyway thanks for replying.
|
|
|
|
|
Hello,
Did you make a backup? VS 2005 asks this before it converts the file.
Anyway, as Nishant already said it: fix the errors and use the better compiler. The standard conformance is far better than any previous compiler written by Microsoft.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote: Did you make a backup? VS 2005 asks this before it converts the file.
In the updrade log generated by VC 2005 it is said there is a backup sln file in the project directory.
It is called myproject.sln.old but I can't find it even in the hidden files.
Do you have any idea?
|
|
|
|
|
Hello,
Did you save the converted solution to another directory? Otherwise I don't know where the file might be.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi, i am using WM_QUERYENDSESSION to check that system is shutting down. But i am unable to differentiate whether system is shutting down or restarting. Is there any way to find this out.
Thanks.
|
|
|
|
|
i am pretty sure that there is no clean way to do it, and i remember a discussion where some of MS guys agreed with that.
now, ExitWindowsEx API takes a flag which specified the type of shutdown, so maybe you could dissasemble the function and see what it really does.
|
|
|
|
|
Probably there is no way to find out the difference
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi everybody!
I need to write a program that will differentiate expressions. The input to this program will be a series, each representing an infix expression to be differentiated.
First the program will have to scan the infix expression, building up an appropriate binary tree representation of it. Once the binary expression tree is built, traverse it, building up an other binary expression tree, which represents the derivative of the original expression.
Finally, once the binary expression tree for the derivative has been built, print the expression...
|
|
|
|
|
homework, huh?
first, you will need to parse the expressions. you can find some implementations here:
http://www.codeproject.com/cpp/rwformulaparser.asp
http://www.codeproject.com/cpp/FastMathParser.asp
http://www.codeproject.com/cpp/MathieuMathParser.asp
second part should be easier, but you can find a Java implementation here:
http://cs.jsu.edu/mcis/faculty/leathrum/Mathlets/src/ (look for 'Derivative Calculator' near the bottom of the page)
also, have a look here:
http://fermitools.fnal.gov/abstracts/mxyzptlk/abstract.html
|
|
|
|
|
Hi ,
I have a VB active X control which has a few buttons on it. I have added the Tab order for these buttons.
I am using this ActiveX on a VC++ dialog. It is a simple dialog application.
and the Active X control is the only control on the VC++ dialog.
When I launch the application the focus does not go to the First button on the VB ActiveX.
I have found that the User control(Active X) gets the focus and not the First control on the User Control.
Can anyone help me out with this(Do I need to set any property??)
Thanks,
Gayathri
|
|
|
|
|
eg.
IXRect *pRect
IXRect *p;
mDoc->get_Rect(&p);
pRect = p;
pls see above the code. whenever i change the member value of p, mDoc.Rect values are changed. also how to avoid it.
i want to copy values only from mDoc.Rect Object to p . how to do
shadrach
|
|
|
|
|
It all depends how mDoc->get_Rect is implemented, it seems like it is returning the address of existing "rect" hence both the objects are pointing to the same content and hence you are having the problem.
-Prakash
|
|
|
|
|
I come from a java background where Exceptions are heavily used. I started using try/catch(...) in C++, but not sure what all can be done in the catch block.
1. What does the elipsis (...) mean? What else can be put here?
2. If we want to catch an exception of a known type, can we specify the exception in the catch here?
3. If so, how do you define an exception class? Is there an interface that we should implement?
4. When we have the elipsis(...) how do you get the details of the exception?
5. Are there simple examples anywhere that demonstrate exceptions in C++ for Java programmers?
thanks!
|
|
|
|
|
1. it means that any possible exception type will be caght there
2. yes, like this: catch (MyException& e)
& operator is not necessary, but it is a good programming practice regarding performance
in c++ you can also catch integral types, like: catch (long x)
3. any class/type can be exception tpye, but maybe you would like to have look at the 'exception' class, which is a base class for all exeption classes in standard c++ library
4. as far as i know, there is no portable way to do it.
5. these are not specifically for java developers but it is not that hard.
http://cis.stvincent.edu/swd/except/except.html
http://cplus.about.com/od/beginnerctutorial/l/aa122202a.htm
there is also a lot of in-depth articles on exceptions at Guru of the Week[^] and here on CodeProject
|
|
|
|
|
Zdeslav Vojkovic wrote: yes, like this: catch (MyException& e)
& operator is not necessary, but it is a good programming practice regarding performance
The example[^] here uses a pointer to the exception object, whereas you are using a reference. What is correct? or does it depend on what is being "thrown", but you dont always have cotnrol over what is thrown, right? When it is a pointer, is it considered as an integral datatype exception?
Zdeslav Vojkovic wrote: in c++ you can also catch integral types, like: catch (long x)
Does this work like this:
try {<br />
throw 5;<br />
}catch(long x) {<br />
printf("%d", x);<br />
}<br />
Does this print 5?
Zdeslav Vojkovic wrote: as far as i know, there is no portable way to do it.
Can you tell me how you would obtain the exception info when using Microsoft Visual C++?
Zdeslav Vojkovic wrote: 5. these are not specifically for java developers but it is not that hard.
Sure, I will go throught them.
thanks!
|
|
|
|
|
Britley wrote: The example[^] here uses a pointer to the exception object, whereas you are using a reference. What is correct?
if an exception is allocated on the heap (using 'new' operator), it must be caught through a pointer. however, this is not a good practice because it is not obvious to the client code how to handle it, and it complicates the deleting of the allocated exception instance (who will call delete on it). exceptions shoud be stack allocated, thrown, and caught by reference. please note that the example is for an MFC client, and MFC implements somewhat specific idiom, where exceptions are allocated on the heap and you have to call Delete() method of the CException class to destroy the instance.
Britley wrote: Does this work like this:
no, because 5 is an int, not a long, but this does:
try {<br />
throw 5L;<br />
}catch(long x) {<br />
printf("%d", x);<br />
}
Britley wrote: Can you tell me how you would obtain the exception info when using Microsoft Visual C++?
when you catch exception with (...) you can't do that. anyway, in this case you should always rethrow the exception, because it is not possible to correctly handle an exception without knowing its type. you can retrieve some exception info, but all the ways i know are OS specific, and not supported by standard c++. for more details, look here:
http://www.codeproject.com/cpp/exceptionhandler.asp
http://www.codeproject.com/debug/XCrashReportPt2.asp
and lots of other exception handling articles on codeproject
what you can do is to catch specific exceptions. example:
catch(exception& e)
this will catch all the exceptions of type 'exception' and of all types derived from it . exceptions are usually modelled in hierarchies, so you can handle multiple exception types in one handler.
|
|
|
|
|
Thanks for the great information.
Zdeslav Vojkovic wrote: if an exception is allocated on the heap (using 'new' operator), it must be caught through a pointer.
Why must? Why cannot it be accessed through reference? I mean, you catch what is thrown. So if you throw the object by dereferencing the pointer, you may catch it through reference. Isnt this correct?
Zdeslav Vojkovic wrote: however, this is not a good practice because it is not obvious to the client code how to handle it, and it complicates the deleting of the allocated exception instance (who will call delete on it).
I can see the complication, which doesnt exist in Java due to its automatic garbage collection.
Zdeslav Vojkovic wrote: exceptions shoud be stack allocated, thrown, and caught by reference.
This is what puzzles me. If the exception is stack allocated, should we make sure the catch statement is in the same scope(braces) as that of the exception variable? Otherwise, how is the stack cleaned up when the control moves out of the scope?
Zdeslav Vojkovic wrote: MFC implements somewhat specific idiom, where exceptions are allocated on the heap and you have to call Delete() method of the CException class to destroy the instance
I see. What is the equivalent for the C++ "exception" class to free the object? Btw, this Delete method of CException might destroy the instance to free up resources, but is the object itself freed too (perhaps through 'delete this')?
thanks!
|
|
|
|
|
Britley wrote: Why must? Why cannot it be accessed through reference?
because T* can't be treated as T, while T& can (they are interchangeable).
T x;<br />
T& ref = x;
T* ptr = x;
Britley wrote: If the exception is stack allocated, should we make sure the catch statement is in the same scope(braces) as that of the exception variable
no, catch statement can be at any level higher than the current context. implementation of stack unwinding is left to compiler vendors, so there is no single answer for that. VC++ creates temporary object which will be thrown, and destroys it after the stack is cleaned up
Britley wrote: What is the equivalent for the C++ "exception" class to free the object?
delete operator.
Britley wrote: Btw, this Delete method of CException might destroy the instance to free up resources, but is the object itself freed too (perhaps through 'delete this')?
it depends. CException constructor takes a BOOL parameter which states whether it is an auto-delete exception. if set to true, Delete() does nothing (this is used for CException instances allocated on the stack). if it is set to false (for heap-allocated instances), Delete() must be called, and it will call 'delete this' internally.
|
|
|
|
|
Zdeslav Vojkovic wrote: because T* can't be treated as T, while T& can (they are interchangeable).
I meant this:
<br />
try {<br />
T *t = new T;<br />
throw *t;<br />
}catch(T& te) {<br />
}<br />
Anything wrong, other than the memory leak, ofcourse?
Zdeslav Vojkovic wrote: What is the equivalent for the C++ "exception" class to free the object
Zdeslav Vojkovic wrote: delete operator.
but for objects created on stack I guess the compiler frees it eventually, so we dont need to call the delete operator. Why do you need to call Delete on the MFC CException again? May be its MFC specific logic...
thanks!
|
|
|
|
|
Britley wrote: Anything wrong, other than the memory leak, ofcourse?
no, that's completely valid.
Britley wrote: Why do you need to call Delete on the MFC CException again
actually you don't, but the problem is that if you call an MFC function which throws a CException*, you don't necessarilly know how it was allocated, so you can't call 'delete ex' because it will crash for stack allocated object, and if you fail to call it for heap allocated object you have a memory leak. Therefore, you must call Delete(), which knows whether to destroy the object or not. if you are 100% sure that it is stack-allocated, you can omit Delete() call, but still you can't be sure if next version of MFC will behave differently and then you would have to modify the code to avoid memory leak.
|
|
|
|
|
Britley wrote: What is the equivalent for the C++ "exception" class to free the object?
The C++ Standard Library throws objects of classes derived from std::exception , not pointers to them, and you should catch them by reference. You don't free the object.
|
|
|
|
|
Zdeslav Vojkovic wrote: 3. any class/type can be exception tpye, but maybe you would like to have look at the 'exception' class, which is a base class for all exeption classes in standard c++ library
To avoid confusion since he is coming from a Java background: In C++ the class does not have to derive from Exception to be thrown. Any type can by thrown.
Jared Parsons
jaredp@beanseed.org
http://jaredparsons.blogspot.com/[^]
|
|
|
|
|
Britley wrote: I started using try/catch(...) in C++, but not sure what all can be done in the catch block.
1. Anything that is holy, practically.
Britley wrote: 1. What does the elipsis (...) mean?
(...) Catch any exception that occurs
Britley :->wrote: What else can be put here?
A known exception type can be put here which has to be caught. Eg: catch(CFileException Cfe)
Britley wrote: If so, how do you define an exception class? Is there an interface that we should implement?
There are a bunch of exceptions. You will not need to implement any interface. You can use any existing exception.
Britley wrote: 4. When we have the elipsis(...) how do you get the details of the exception?
There is one API call known as GetLastError for this purpose
Britley wrote: 5. Are there simple examples anywhere that demonstrate exceptions in C++ for Java programmers
<br />
TRY<br />
{<br />
CDatabase DB;<br />
CRecordset Rc;<br />
CString szSql = "SELECT * FROM MYTABLE WHERE AGE = 20"<br />
DB.ExecuteSql(szSql);<br />
}CATCH(CDatabaseException CDbe){ AfxMessageBox(CDBE->m_error));}<br />
I believe above things are right. I a newbie too, but have worked on a database module. I am sure you will get a bunch of replies and guidance.
Aljechin Alexander
|
|
|
|
|
Aljechin wrote: Eg: catch(CFileException Cfe)
it is a bad practice to catch exceptions by value (except for integral types)
Aljechin wrote: There is one API call known as GetLastError for this purpose
it will not return details of exception. it is a Win API to retrieve last Win32 error for the current thread.
also, microsoft specific TRY/CATCH should be avoided, and standard try/catch used instead, for reasons stated here[^]
|
|
|
|
|