The purpose of delete is not to delete things. What?? But I'm serious. The purpose of delete is to undo new.
As an approximation that will no doubt anger several C++ experts, you can view new as a combination of malloc and invoking the constructor, and you can view delete as a combination of invoking the destructor and free. That's not exactly literally how they work, but it's close enough that you can use that to reason about when you need them. (don't use this as an excuse to delete something that was malloc'ed)
Most of the time, if you want to get rid of something, delete is the wrong way to do it - because most things were not created by new. Trying to delete something else results at best in a failing safety check but in general corrupts the state of your application.
Most objects are destroyed implicitly, in various ways. Local variables by exiting a scope, values in containers by the container being destroyed, smart pointers do most of the rest. Explicitly using delete is occasionally necessary but it's probably better to actively avoid creating those cases. It's quite bug-prone, especially around exceptions and other non-trivial control flow.
Calin Negru wrote:
later if you use “delete” on the pointer will that delete the content of the variable too?
In the sense that its destructor is invoked (so you can implement it and delete the members that need to be deleted), yes. If you mean that in some other sense then, probably, no (but depending on what you mean).
Implementing classes with lots of raw-pointer members that you individually delete in the destructor is very mid-2000s. Typical advice is to delegate that to smart pointers and containers as much as possible, with the goal of following the Rule of Zero instead of one of the other rules-of-some-number, but sometimes you just have to do what you have to do.
Have you even looked at the documentation for QDebug?
QDebug &QDebug::operator<<(QChar t)
Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent it.
which leads us to:
Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream.
When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.
If you need quoted output, its simple enough to do it yourself, just escape the quotes (\") or use Raw literals e.g. std::string hello(R"x("Hello World")x") assigns "Hello World", *including the quote marks" to the variable hello,
NB. I have not tried this. I do not use QT. I don't know if this will achieve what you want. I do know how to use google, though. It's more than time enough that you did too.
Hello. I apologize in advance if I created the topic in the wrong place, because I think that my task is directly or indirectly related to WinApi. I will describe the task:
I am programming an imitation of manual work in applications for working on financial markets (Metatrader 4 and 5). I use AutoIt for this. I need to read the text of the SysListView32 items .I wrote the following code for this purpose .
Local $pid= ; here i write id of needed process
Local $hwnd= ; here i write handle of SysListView32
Local $maxtext= ;here i write max number of chars
Local $rectext=DllStructCreate("char ["&$maxtext&"]")
The problem is that the above code only gets text of items if the SysListView32 has either LVS_OWNERDATA or LVS_OWNERDRAWFIXED style. I have checked above code on different applications with SysListView32 that only had style LVS_OWNERDATA and checked above code on different applications with SysListView32 that only had style LVS_OWNERDRAWFIXED. In both cases i was able to get text from SysListView32 items. But above code is not getting text of SysListView32 items with combined LVS_OWNERDATA and LVS_OWNERDRAWFIXED styles . The SysListView32 of Metatrader application have combined styles LVS_OWNERDATA+LVS_OWNERDRAWFIXED.
Well here's the question:
How to get item text from SysListView32 from another application with both LVS_OWNERDATA and LVS_OWNERDRAWFIXED styles at the same time?
I would like to get some direction of action or example code (doesn't matter on AutoIt). Thank you.
I am not sure that you can get the information. When a view has one of the OWNERDRAW settings it does not have a backing list of items. As the view tries to display its contents it sends a message to the parent Window which tells the application to return the text for each item. So it is the application that holds the actual data, not the ListView.
There is no standard way of doing that. The data backing the owner-draw can be stored any way the application needs. It can be, literally, stored anywhere, in any format, with no public API to get at it.
Think of how you store data in your own applications. Do you expose that data in standardized ways across all of your applications? Do you expose that data in a public API? Of course not!
How can you insert the elastic walls of the snooker table and make all the 16 balls move and bounce off the walls?
Can someone pliz help me with the code of a functional snooker game using C programing.
Sorry this site does not provide code to order. To creatre such a program would need a good knowledge of C programming, general GUI processes and (probably) Windows GDI+ or Direct2D. This is not something that you could create in an afternoon.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
1. Learn basic C
2. Learn how to get and use some additional basic libraries for C.
3. Learn basic UI interactions.
4. Draw some basic shapes using 1-3 on your monitor which are sort of like what you want. It will improve later.
5. Learn collision mathematics and how it relates to games. This is not going to be simple. You could skip this and just guess unless you really want it to look right.
6. Create actual program by breaking into parts. For smooth movement you are going to need how to make the graphics move incrementally. This can either be simple (but jerky) or you can spend a lot of time learning it.
It returns an int. That int is similar to what you would get from open(2), and can be used in many places any other file descriptor could be - e.g read(2), write(2), and, of course, close(2). I think that some fcntl(2) operations are also valid for socket fds. But you'll probably get a error if you try to use lseek(2) on a socket. If you prefer, its a file descriptor that describes a socket. Just like open("/dev/ttyS0", O_RDWR) returns a file descriptor that describes a serial port and open("data.txt", O_WRONY|O_CREAT, 0660) returns a file descriptor that describes (presumbably) a text file in the CWD, or open("/tmp/mypipe", O_RDONLY) returns a file descriptor that might be a named pipe.
NB: in the notation open(2) the (2) refers to the manual section that describes the system. So for example man 1 stat produces the man page for the stat command, whereas man 2 stat produces the man page for the stat system call.