|
It was more of a clarification of what seemed to be a general statement that could be interpreted as "a default assignment operator does nothing".
|
|
|
|
|
I see. I didn't read it as a general statement, but I now recognize it might be considered as such. Good point.
|
|
|
|
|
You do make a good point, so I edited my response to clarify.
Thanks for keeping me honest.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
get() = argh; calls bclass::operator= which doesn't exist*. Even if it did exist, val is not a member of bclass and thus couldn't be copied anyway. If you define the return type of get() as dclass&, and in addtion to that define the assignment operator for this class, then it might work.
P.S.: to my knowledge assignment operators can't be made virtual, but you might be able to get this to work with a trick like this:
class base {
virtual void assign(const base& other)=0;
public:
base& operator=(const base& other) { assign(other); return *this; }
};
class derived : public base {
virtual void assign(const base& other) {
const derived* pOther = &(dynamic_cast<const derived&>(other));
if (pOther != 0) {
val = pOther->val;
}
}
public:
derived() : val(5) {}
int val;
};
derived myglobalderived;
derived& get() { return myglobalderived; }
void test() {
derived mylocalderived;
mylocalderived.val = 3;
get() = mylocalderived;
std::cout << "get() = " << get().val;
}
*P.P.S: while bclass::operator= hasn't been defined explicitely, the compiler might create one automatically (but it wouldn't make any difference as explained above). I am not sure in this case however, since assignment operators can't be virtual, and bclass is an abstract class. A member-wise copy will not make any sense, as you can't create instances for an abstract class, and derived classes will overwrite, not override the assignment operator.
modified on Thursday, January 27, 2011 5:58 AM
|
|
|
|
|
My TCP/IP program transfers large data between client/server frequently.
I want to compress data to reduce transferring amount and increase transferring speed.
So I need simple, fast and efficient source code to compress/decompress data, winzip is too slow because it considers many things, which are useless for me, such as file structure.
Do you know any fast compressing source code other than winzip?
Thanks for links or suggestions.
|
|
|
|
|
The only thing I know of is zlib, which also uses the deflate algorithm to compress data. But really the thing that gives you the most control over the speed of the compression is how highly compressed you want it. I think zlib gives you a range of 1-9 for speed vs compression where 1 is the fastest but results in the largest size and 9 gives the smallest size but at the cost of time.
I think though, that if you do some quick checks on the data you want to compress then you can save some time yourself, JPEGs and PNGs are already compressed for example so it would be a waste of time to try and compress that data, and you would be better to just send it as-is.
|
|
|
|
|
|
I have two different applications appDad and appKid. appDad is a Windows Forms Application and it calls appKid.exe. appKid does a series of prinf´s that I want to display in a text box in appDad.
Some suggest that I use FILE * output = _popen ("ls", "r") or freopen ("/dev/tty", "w", stdout) but I´m not quite sure what I´m doing.
Am I being lazy for asking instead of researching a bit more? I hope not...
|
|
|
|
|
See here and here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Ok, thanks a lot. But... is there a simpler way to do it in .NET?
|
|
|
|
|
piul wrote: But... is there a simpler way to do it in .NET?
.NET is a framework, not a language. If you are referring to Managed C++, see here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
How to get a CBitmap from a LPDIRECTDRAWSURFACE7 ?
modified on Thursday, January 27, 2011 10:10 AM
|
|
|
|
|
Try something like this:
1. Use IDirectDrawSurface7::GetSurfaceDesc[^] to get the dimensions of the surface.
2. Use IDirectDrawSurface7::GetDC[^] to get a device context for the surface
3. Use CBitmap::CreateCompatibleBitmap[^], specify the DC you got from the surface, you might use CDC:Attach[^] to get a CDC from the HDC, just don't forget to also Detach it before releasing the DC. The dimensions for your bitmap you got in step 2.
4. Create a DC compatible with the surface DC using CDC::CreateCompatibleDC[^]
5. Select the bitmap you created in step 3 into the DC you created in step 4. Do a bit-block-transfer with CDC::BitBlt[^] to move the pixel data from the DC you got in step 2 to the DC you got in step 4.
6. Deselect the bitmap (3) from the DC (4), destroy the DC (4)
7. Use IDirectDrawSurface7::ReleaseDC[^] to free up the DC you got in step 2.
8. Live happily ever after.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Hi thx for the awnser.
I haven't got it to work yet a get an assertion error when calling CreateCompatibleBitmap()
Not sure I do the right thing when geting CDC object.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pCDC);
dcMemory.SelectObject(cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,pCDC,0,0,SRCCOPY);
pCDC->Detach();
dcMemory.Detach();
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
|
|
|
|
|
Instead of this:
kagelind wrote: CDC *pCDC = CDC::FromHandle(sourceHDC);
pCDC->Attach(sourceHDC);
do this:
CDC surfaceCDC;
surfaceCDC.Attach(surfaceHDC);
Use &surfaceCDC everywhere you used pDC.
Then instead of this:
kagelind wrote: pCDC->Detach();
do this:
surfaceCDC.Detach();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
also, instead of this:
kagelind wrote: CBitmap *cBmp;
cBmp->CreateCompatibleBitmap(pCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
do this:
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&surfaceCDC, SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
and use &cBmp everywhere you need its address.
Also, when you select the bitmap into the dcMemory, store its old CBitmap and select it back into the memory DC before destroying it or you might end up leaking handles. So something like:
CBitmap *originalBmp = dcMemory.SelectObject(&cBmp);
...do what you need...
dcMEmory.SelectObject(originalBmp);
dcMemory.DeleteDC();
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
The code runs now but don't seems to work.
DDSURFACEDESC2 SurfaceDesc;
m_pDrawSurface->GetSurfaceDesc(&SurfaceDesc);
HDC sourceHDC = NULL;
m_pDrawSurface->GetDC(&sourceHDC);
CDC SurfaceCDC;
SurfaceCDC.Attach(sourceHDC);
CBitmap cBmp;
cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC(&SurfaceCDC);
CBitmap * orginalBmp = dcMemory.SelectObject(&cBmp);
dcMemory.BitBlt(0,0,SurfaceDesc.dwWidth,SurfaceDesc.dwHeight,&SurfaceCDC,0,0,SRCCOPY);
SurfaceCDC.Detach();
dcMemory.SelectObject((HBITMAP)orginalBmp);
dcMemory.DeleteDC();
m_pDrawSurface->ReleaseDC(sourceHDC);
If I try to save the CBitmap a get an assertion error. It looks like the HBITMAP is NULL
CImage saveImage;
saveImage.Attach(cBmp);
saveImage.Save(_T("test.bmp"));
saveImage.Detach();
|
|
|
|
|
Does this succeed:
kagelind wrote: cBmp.CreateCompatibleBitmap(&SurfaceCDC,SurfaceDesc.dwWidth, SurfaceDesc.dwHeight);
?
This:
kagelind wrote: dcMemory.SelectObject((HBITMAP)orginalBmp);
is completely wrong, it should be:
dcMemory.SelectObject(orginalBmp);
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
|
Glad it works.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
I want to study how to write my compiler, so need a open source compiler for study.
The GCC is too big. is there simple compiler?
|
|
|
|
|
Have a look at:
- LCC[^] (consider buying the book).
- TCC[^].
A nice reading (oldie-goldie) is Let's Build a Compiler - by Jack Crenshaw[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I can strongly recommend that you read the Dragon Book[^]. Writing a compiler is both simple and really complex at the same time. This book guides you through language definition, lexical analysis, syntax analysis and finally code generation. It also has advanced sections for related technologies.
With this book as a guide, writing a simple compiler from scratch is not too much work, and gives a great understanding of languages and compilers. This is not really an answer to your question, but still...
|
|
|
|
|
I am currently trying to convert a string that resides in a _bstr_t variable vFieldDate into a char array. I have found that I can type cast this via the (char *) with a variable I named holder which is a pointer to a char. The issue I am having a hard time solving is how to convert this to a char that can be stored within the char Date[ARR]. When I attempt the following code I get the compilation error "Cannot Convert From Char * to Char. How do I extract the value that resides in the holder location and save it into the array?
Date[cyc] = holder;
The below portions of code are a part of an ADO program that is accessing data from a database.
char Date[ARR] = {};
_bstr_t vFieldDate;
vFieldDate = rec->Fields->GetItem("Date")->Value;
char *holder = (char*)vFieldDate;
|
|
|
|
|
This question has been anwered with:
#include <cstring>
//...
strcpy( Date, holder );
|
|
|
|