Comment from Author:
In the column from last week, we covered tiff’s problem. Here, he was looking for the _mbstowcsz() function in VC7. But, unfortunately, he could not find any solution. So, I asked you this question, but unfortunately I got no replies. I searched, too on, the net, but could not find the function in VC7.
Introduction:
Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:
- What is the difference between “C”-like type conversion and VC++ cast operators?
- Is it necessary to delete a created pen?
- Is it possible to re-sort a map using an another key?
- Does the STL contain a matrix class?
- Is it necessary to delete an object from std::list?
|
Thread:
reptile asked an interesting question. He wants to know the difference between a C-type conversion and a VC++ comparision. Do you know the difference?
Is there any difference between "C"-like conversion and VC++ cast conversion operators (reinterpret_cast, dynamic_cast, static_cast)? I don't mean a logical difference, I mean low-level code generation differences. Maybe cast conversion operators are used just in help for programmers?
- In C, the conversion will be done assuming that the casted object or variable is of a type in which it is casted. If it is not, your program can crash.
- The C++ conversion includes additional information to each variable or object. It tests whether the cast is possible. If not, it returns NULL. You can test the result against NULL and assert.
|
Thread:
Gyannea needs to know whether is it necessary to delete a Pen?
If I create a Pen with
hpenl = CreatePen(PS_SOLID, 0, color1);
and select that pen and then
hpenl = CreatePen(PS_SOLID, 0, color2);
and select that pen, can I delete a single pen or will there be a second undeleted pen out in never-never land?
It is ALWAYS neccesary to delete a Pen created with DeleteObject because the Windows GDI objects are limited resources. If you don’t free an object with a call to DeleteObject every time you create a new object, you will at some time run out of resources. This will cause problems with programs other than your own.
Always remember that the allocated GDI objects are not freed when the program exits. These remain allocated until a reboot.
|
Thread:
ilamparithi is working with an STL Map. He has already inserted all data in the map and now he wants to re-sort the map using an another key. Is that possible?
Hi All, After all the datas are inserted into the MAP, is it is possible to re-sort the MAP using some other key?
No, this is not possible. An std::map is always sorted by the key type that is given to it at compile-time. The only way you can sort by something else is to copy the contents to a new map or vector, which then is sorted on a different key or you have to delete the old key and reinsert the data with a new key.
|
Thread:
LudaLuda needs a matrix class. Now he wonders whether he can find it in the STL.
Does anyone know what header file needs to be included to use the matrix class? ex: Im trying to use
matrixx(2,3)
Is there an STL class? Does VC++ 6 include a class? It's supposed to create a 2D int-array with 2 Rows and 3 Columns.
Well, the STL does not contain such a class and VC++6 also does not contain a class. You can use a vector to create a 2D array. Take a look at the following faq. And, if you really need a seperate class for that, you can download one here.
|
Thread:
Miran created an STL list of objects. Now, he wants to know whether remove will only remove the object from the list or it will also free the memory dynamically allocated for a MYSTRUCT object in AddObject function? Because the code is very long, I only show a small part of it. But, to understand the whole scenario, I suggest you read the whole thread. Paul McKenzie and Philip Nicoletti explained the problem in detail.
// MYSTRUCT = A simple structure.
// g_MyStructList = ..std::list<MYSTRUCT*> g_MyStructList;
void AddObject(LPSTR lpstrFile, DWORD dwSize, BOOL bFlag)
{
MYSTRUCT* pMySrtuct = new MYSTRUCT;
pMySrtuct->strFile = lpstrFile;
pMySrtuct->dwSize = dwSize;
pMySrtuct->bFlag = bFlag;
g_MyStructList.push_front(pMySrtuct);
}
Well, the displayed code above does not store objects; instead, it stores pointers. There is no need for delete if you store objects. You do not “delete” objects from the list unless the “object” is a pointer to dynamically allocated memory. The simple rule is this: If you call “new”, you are responsible for calling “delete”. If you didn’t call “new”, you don’t call “delete”.
Take a look at the whole thread to read more about this interesting question.