thelamb 163 Posting Pro in Training

You have already done it...

Look at how you declare your 'request':

Request *request=new Request();

So 'request' is now allocated on the heap.. means you are responsible for cleaning it up (delete request; somewhere in the code).

Then, you say.. ok I want 'request' to point to a LoginRequest.

LoginRequest loginRequest;
request=&loginRequest;

So you are overwriting the previous pointer to 'new Request();' with a pointer to a local variable loginRequest.
Since loginRequest is local, it will be destroyed when it goes out of scope. Now your 'request' pointer points to garbage and there is no way that you can delete the original new Request()(remember you overwrote the pointer), so you have yourself a memory leak.

So I dont really understand why you do the first "new Request();".. doesnt this make more sense:

Request *request=new LoginRequest(); // I guess LoginRequests inherits from Request?
request->tcpMessage=line.toUtf8();
request->decodeFromTcpMessage(); 
if(request->requestType==REQUEST_LOGIN)
{
    requests.enqueue(request);
} else  // Request is not a LOGIN_REQUEST
{ 
     delete request;
}

// When you destroy the requests.. dont forget to delete the pointers.

P.S. think about your naming convention...
Is using 'requests' and 'request' a good idea? The names look very simmilar and just introduce confusion.

metdos commented: Good Point +1
thelamb 163 Posting Pro in Training

You can't get root2 to output.... are you sure that you are entering values for A, B, C etc. so that Discriminant is 0? As when it's > 0 only Root1 is printed of course.

Also have a look at how you check if 'A' is non-zero. What happens if I enter a non-zero value twice in a row? Validating user-input is a very important aspect of coding, and a lot of people think lightly about it but they absolutely shouldn't.

Another note on your code... You want to check if Discriminant is < 0, == 0 or > 0... so you start with checking < 0.
If this is true ( Discriminant < 0 ), what can you say about the 'Discriminant > 0' and 'Discriminant == 0' checks? Are they useful?

thelamb 163 Posting Pro in Training

Application that use system() to clear the screen are a downright pain in the ass, excuse my language.

As a user of the application, I might have some 'important' information on the console before running the application, if the application 'clears' the screen with system() all of this is gone.

William Hemsworth commented: Yup yup. +5
Ancient Dragon commented: good point :) +25
thelamb 163 Posting Pro in Training

This is a typical answer that can be found through 2 seconds of googling.

http://www.cplusplus.com/reference/clibrary/cstdlib/system/

Though I generally think calling system() is a bad design, the overhead is massive and mostly there are much better alternatives.

thelamb 163 Posting Pro in Training

You have to delete it at a point where you can guarantee that after the delete you won't access it anymore.
This can be at the end of an application, in the destructor of a class or just somewhere in a function that prints the variable and is then done with it.

thelamb 163 Posting Pro in Training

That's not really how it should work. It is good that you include the entire project so that we CAN download and compile it entirely. But that shouldn't be necessary if you give us a clear description of the error and paste the code where the error is occurring (paste the function where the error is and any relevant code we might need to see). Then if this code isn't enough to solve the problem we will download the whole source and look at it.

No offense intended but if you ask your questions like this it only looks like you are asking for others to do your homework. So please copy/paste the error and relevant code (with code tags of course) and tell us a little what you think the error could mean, so that we can see that you have actually thought about it (this is the most important part). Right now we are completely in the dark about what you have tried, what the error is about and we even still need to fix the first 3 errors before we come to the point where we can start helping you?

thelamb 163 Posting Pro in Training

Why do you expect others to do your homework? This approach will never work out on these forums.

Instead show us that you have done some effort and explain what you are having problems with. You say you have fixed 4 out of 16 problems, that means all the other 12 errors you can't fix? Or did you stop trying when you couldn't fix the 5th error.

A better approach would be to paste the error you are getting and paste the code where the error occurs. Then write something what YOU think is wrong and show that you have actually thought about the problem, then we can give you a hint on how to solve the error.

After all you are in school to learn, not to let others do the work for you and copy it.

Salem commented: Well said +36
thelamb 163 Posting Pro in Training

It indeed depends on how the LPDIRECT3D9 is defined, normally you will find a structure definition like:

struct _MYSTRUCT 
{
[indent]int myInt;
string myString;
[/indent]
} myStruct, *pmyStruct;

And then (I think just as a matter of preference) you can define something like LPMYSTRUCT as a pointer to the myStruct.
I use this a lot because I like it more than having *, for example:

typdef unsigned long DWORD, *PDWORD;

will define DWORD as unsigned long and PDWORD as unsigned long pointer. Saves me typing and it's personally more clear to me where I'm using pointers.

kvprajapati commented: Good point. +10
thelamb 163 Posting Pro in Training

Also depends on how much you are printing. Using endl can significantly slow your code if you are printing alot.

As an example when I started out with c++ I did some exercises on projecteuler.net, constantly printing in a while loop, I was blown away when at some point I decided to use '\n', and the algorithm finished in a mere seconds as opposed to minutes.

athlon32 commented: It was a great post...a lot of help :D +1