|
I believe when an object gets assigned to a STL container, it gets copied into it. Your class does not have a "custom" copy constructor or a "custom" assignment operator.
-- modified at 11:59 Thursday 4th October, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Perhaps not. The default would be used and the object in the container would have copied the pointers and since in his main code the Patient is still on the stack the pointers would be good. Of course he needs deep copy and assignment but appears to be a student so I would be surprised if he has any idea of this stuff.... yet.
|
|
|
|
|
True. It just makes me nervous to see classes working with memory allocation w/o a copy constructor and a assignment operator. Also, he has no destructor to clean up.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Well hopefully he will have a better understanding of such things by the end of the course.
|
|
|
|
|
For compiler errors you need to post the error message.
A wild guess based on your code is the output stream knows how to output an int but doesn't know how to output a Patient.
|
|
|
|
|
At a guess, I would say your Patient needs to define an “<<” operator that uses “std::stringstream” internally to convert the data to a string that is returned for “cout” to process. I could be wrong as do not remember doing that before, so look around for an example.
What worries me more is what the Patient’s destructor does, as you did not show it. In your code you have two Patients’ and they both contain memory pointers to the same address. You have the original and the copy in the “deque”, when they go out of scope then the destructor will be called for both of them. That means that the same memory will be being freed twice, always a bad idea. Also if the original Patient was created in a different scope and goes out of scope before the “deque” does, the pointers in the copy, contained in the “deque” will be pointing to unallocated memory or memory that is being used my someone else; very, very bad thing.
You need a copy constructor the makes a copy of the original by allocating new memory for the data. This can be done by simply duplicating the code in “Patient(char*,char*,char*)” within the copy constructor.
Additionally you need to make sure that the “char*” passed points to something before calling “_strdup”, as I do not know what will happen if it points to NULL. Also before you assign a new address to a pointer in your methods/functions, you need to make sure that if the pointer is already assigned to a different address that it is freed before making the new assignment.
Of course you could eliminate all that pointer stuff by simply using the “std::string”, instead of handling yourself. It will handle all the memory allocation and copying for you and make the code much cleaner and easier to read.
Properly applied, usage of the STL can eliminate most, if not all, of the memory allocations you need. Take full advantage of “std:string”, “std::vector”, and other containers; after all that are what they are for.
Well that ends today’s lesson. I hope it helped.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I will probably fix the destructor stuff later. I THINK the program crashes because it is recalling non-existant values from the patient class that no longer exist or out of scope. I originally tried to define the deque with the definition of the doctor class (doctor.h) below:
#include "Patient.h"
#include <deque>
<p></p>
class Doctor {
<p></p>
private:
char* LastName;
char* Room;
char* Code;
deque<patient> PatientQue;
<p></p>
public:
Doctor();
Doctor (char *, char *, char *);
void SetName(char *);
void SetRoom(char *);
void SetCode(char *);
void SetPatientQue (Patient);
char* GetName();
char* GetRoom();
char* GetCode();
Patient GetPatientQue();
};
If I could define it here, then I think my problem would be solved. However, I get an error message, something about a semicolon that is expected before the "<". All the other code within the doctor procedure was just a work-around because this did not work.
Do you know how to define a deque within the class header?
|
|
|
|
|
I have seen that error many times, but all I know at the moment is that something is missing. The error message is [technically] wrong! My first thought was that you did not use “std::deque”, or a using statement (I never do in C++), but that was wrong. Look in your header file and try to see if you are missing something; that is my first reaction. Beyond that I do not know, because I have always found the problem and did not bother to think about it beyond that. You have a syntax error, some minor one, but one just the same.
As noted in my last post, I highly recommend that you stop using “char*” and start using “std::string” for the reasons I gave. The method in your original post mixed C and C++, and the C++ solution (STL) for handling strings is much better if memory allocation is involved.
If you gave the error number it might help a little, and I stress little, because the description you just gave (this time) is good enough. The exact cause could be a number of things (I think), but unless you (meaning myself) are the one doing the debugging, it is unpredictable.
Most of the time that you find yourself doing a work-around, there is something wrong with the original code or you are making some minor mistake (which I do not see).
I know that was of no help, but please consider what I said about “std::string”. Even if you only use them internally to your class, you will save yourself a lot of trouble.
P.S. Also make those parameters constant (“const char*”).
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Got it fixed. I have not programmed in a while so I am out of practice. It was the "using namespace std;" Five days wasted over something that simple
I will add the "const". Thanks.
|
|
|
|
|
what is the API that MS Office is calling to save a file under a different name ?
|
|
|
|
|
It could be any number of functions/methods. Why?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm trying to understand what is the final called API that pops the dialog to select a name for the file. I thought that the GetSaveFileName is the only player in the field.
are there any other ?
|
|
|
|
|
carabutnicolae1234 wrote: are there any other ?
Probably. Office is notorious for using functions and controls that are not available to the rest of us.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What makes you think any APIs are called?
Office uses its own file save dialog so there's probably many dialog-related
APIs used.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I see, thanks.
and is it building the same looking dialog as the standard one ? or it calls it under different name ?
where I can read about this ?
|
|
|
|
|
The dialog Office is using has a similar UI to the common dialog.
Office is a 3rd party app (suite). There's no reason MS would publish how
it's doing its dialogs. I have never seen any documentation on
it.
If the info is public, I imagine it would be available in the
Office development[^] documentation somewhere.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I need to draw on bitmaps buried deep in a DLL and have no access to HDC or HWND
any attempt to GetDC(NULL) returns a valid pointer but all attempts to draw the bitmap fails.
I'm not using MFC, straight SDK.
Has anyone done this before or know how to implement this?
any help would be appreciated.
|
|
|
|
|
What is a bitmap "buried deep in a DLL"?
You only need an HWND if you're doing something window related.
GetDC() is for obtaining a device context for a window (or the screen).
If you're not drawing there, then that's useless as well.
What are you trying to do?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm trying to do on screen display inside a DirectShow filter.
To show buffering messages.
I figured it would be easy to just create a bitmap the size of the output image, then just draw buffering messages and send it off to the render.
|
|
|
|
|
Assuming you want to use GDI to draw on the video frames...
If you have access to the uncompressed frames before they are rendered,
I would use a DIBSection (see CreateDIBSection).
Create a memory DC (CreateCompatibleDC()), select the DIBSection into it.
For each frame, copy the frame pixel bits into the DIBSection's pixel bits.
Then use GDI to draw to the memory DC.
Copy the pixel bits from the DIBSection back to the frame buffer.
Depending on the renderer you are using, there may be features already there
for overlays.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'll try that...
only difrence is i'll have to create the buffer first, take the previous frame and color convert it to rgb24
then pass it into the CreateDIBSection
draw the message I want,
then color convert it to YUY2 or what ever output format is beeing used.
HBITMAP CreateDIBSection(
HDC hdc, // handle to DC
CONST BITMAPINFO *pbmi, // bitmap data
UINT iUsage, // data type indicator
VOID **ppvBits, // bit values
HANDLE hSection, // handle to file mapping object
DWORD dwOffset // offset to bitmap bit values
);
it needs a HDC,
I dont' have one...
How do i get one, or do i need a valid value? (pass in NULL?)
edit: just looked into CreateCompatibleDC.
If this handle is NULL, the function creates a memory DC compatible with the application's current screen.
would that be dependent if someone is running their display in 16,24, or 32bit?
-- modified at 12:35 Thursday 4th October, 2007
|
|
|
|
|
hvanzyll wrote: t needs a HDC,
I dont' have one...
You can pass NULL for the DC when calling CreateDIBSection.
The DC is only used for DIBs requiring a color table, not RGB DIBs.
hvanzyll wrote: If this handle is NULL, the function creates a memory DC compatible with the application's current screen.
would that be dependent if someone is running their display in 16,24, or 32bit?
The DIBSection will determine the bitmap format so a screen compatible
DC will be fine. Note this is NOT the case with regular DDBs (HBITMAP),
which cannot be selected into an incompatible DC.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you for your help on this.
hopefully my schedule will clear up in the next few days and I will get a chance to implement this.
|
|
|
|
|
Hi guys
I am receiving WM_ERASEBKGND in my app's main window event handler. However, i can't find what is in fact sending this event. I know that this may be sent by BeginPaint, when InvalidateRect's last argument is set to true. But, all of InvalidateRect calls in my app are called with false as the last argument, so i know that this is not the case.
Do you know any other functions/cases that are causing WM_ERASEBKGND to be sent to the app?
BR
dwk
|
|
|
|