|
pankajdaga wrote:
Am I missing a design detail here. Are these templated classes never supposed to be derived from. How can I make sure such heritance is safe (in keeping with the design principle here).
You're exacly correct, but see section 1.7 "Destructors of policy classes" for Alexandrescu's solution (so make policy classes destructors non-virtual and protected.
[edit]
Just to add a little more info - you can sucessfully create the object using new, but the subsequent call to delete will be a compiler error, because the base class destructor is protected.
[/edit]
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Yeah, I had made the mistake here:
I had made the dtor of the derived class protected. My bad!
This is a great book! I have learnt so much from just the first chapter. It is heavy reading though, so I am continuing at a slow pace...making sure I absorb most of it.
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hello,
Is there a Windows API that will tell me whether hyperthreading is enabled or not on a PC?
|
|
|
|
|
Are you referring to identifying a hyperthread supported CPU? Check out CodeProject code section.
http://www.codeproject.com/system/camel.asp
Kuphryn
|
|
|
|
|
No, I know it is a hyperthread supported CPU - I just want to know whether it is activated or not.
|
|
|
|
|
Have you gone through this tutorial, specifically lesson 8?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I have now! Thanks very much.
|
|
|
|
|
Hi,
I'm trying to create a library from original source code. The code is not mine and only includes .c, .h, .def files. Hence, no simple project file to load. I create my own empty project and build the library. It seems to do it fine (with a few warnings). However, I create another app which actually uses the newly created library. I get errors when I try to use it. It gives me LNK2001 unresolved external symbol _imp_my_thing. I search for my_thing in the source code of the library and find it is a structure defined as, "extern struct my_thing my_thing;". Do I need to include the .def files when I create the library? Or does the code need to be modified. Thanks.
|
|
|
|
|
Have you tried putting:
#ifdef __cplusplus
extern "C" {
< your function declarations here >
}
#endif
This will keep the compiler from mangling the names. Also, make sure that the library is in the list of libraries to include in the link. (Bet you have done this!)
Larry J. Siddens
|
|
|
|
|
Anonymous wrote:
Or does the code need to be modified
Short Answer. Yes
Longer Answer. The source code for the library expects to be linked with another library that has defined a struct my_thing. If your use of the library does not use any part of this struct, then I would comment out the extern definition, comment out the parts that use it and then rebuild it. Your app should then link okay.
Chris Meech
It's much easier to get rich telling people what they want to hear. Chistopher Duncan
I can't help getting older, but I refuse to grow up. Roger Wright
I've been meaning to change my sig. Thanks! Alvaro Mendez
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
|
|
|
|
|
Hi, i'm currently realy busy on a Vb.Net project and was wondering if anybody could produce a simple multithreaded program for me in visual c++. If u could e-mail me your e-mail address, I will send u the required flow diagram for the structure of the program, would really appreciate it..Thanks again, stevie.
stevie Murdock
|
|
|
|
|
lol, where the hell do u think u are!?
in a supermarket??
do ur homework urself and go away!
Don't try it, just do it!
|
|
|
|
|
|
hah!
You are looking directly at solutions and you do not even realize it.
Sad.
Kuphryn
|
|
|
|
|
|
Cash, in small, unmarked bills. Payment in advance. No refunds.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
...unmarked bills.
Why would they need to be unmarked? It's not like you are stealing them.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
You don't want the Feds tracing your ill-gotten gains, do you?
Software Zen: delete this;
|
|
|
|
|
If you are being paid for the work, how is that ill-gotten gains?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Sometimes, it is necessary to change a floating point number to an integer. The usual way of doing this is just to write
i = (int)f;
However, the C++ compiler also lets one express this desire like this:
i = int( f );
which is how functions are normally written, and it is easier to understand in complicated expressions rather than casts. Similar expressions can be produced with other implicit types eg double and float eg
dbl = double( i );
Does anyone know when it became possible to write the code like this, as opposed to using casts?
Does anyone know if there are any drawbacks or using this approach?
All comments are welcome
|
|
|
|
|
i had a look at this in the disassembler, didnt find any difference!
Don't try it, just do it!
|
|
|
|
|
FearlessBurner wrote:
i = (int)f;
Is a cast.
FearlessBurner wrote:
i = int( f );
Constructs an unnamed (temporary) int, using f as the initialiser value, and assigns/copies the value to i. Your compiler probably optimises this.
FearlessBurner wrote:
dbl = double( i );
Is similar to the previous comment, and constructs a temporary unnamed double.
FearlessBurner wrote:
Does anyone know when it became possible to write the code like this, as opposed to using casts?
Does anyone know if there are any drawbacks or using this approach?
It probably became possible to write this when you changed from C to C++.
My own recommendation is to cast using the C++ casts, instead of the C casts, so for the example above I'd write:
i = static_cast<int> (f);
Because it's easier to find casts that use the C++ syntax for casts over the C syntax, and using the correct C++ cast can reduce or highlight potential errors caused by casting - this particularly applies to the other three C++ casts (const_cast , dynamic_cast , and reinterpret_cast )
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
I have a Listctrl in which i have to do some operation drags the scrollbar(in either direction)
I know that when user drags the bar SB_THUMBPOSITION is generated.But my problem is how do i know in which direction the scrollbar has been dragged.
Any help will be appreciated
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
When you receive a WM_HSCROLL message and the low-order word of wParam is SB_THUMBPOSITION , the high-order word of wParam will indicate the current position. You can keep track of this position and know the direction of the scrolling.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hallo,
has anybody ever encountered a strange problem with LoadImage?
When our application finds bitmap-files with appropriate filenames within a certain directory it wants to use these symbols as treeview icons. We're doing this:
HBITMAP hBitmap = NULL;
CBitmap bmpCmd;
CString strBitmapFile;
strBitmapFile = strCurrentFile.Left( strCurrentFile.GetLength()
-CString(".igl").GetLength());
strBitmapFile += CString(".bmp");
hBitmap = reinterpret_cast<HBITMAP>(LoadImage(NULL,
LPCTSTR(strBitmapFile),
IMAGE_BITMAP,
ImageSize32.cx,
ImageSize32.cy,
LR_LOADFROMFILE));
if (hBitmap)
{
bmpCmd.Attach(hBitmap);
CmdBitmapId=m_ImageList.Add(&bmpCmd, rgbMask);
bmpCmd.DeleteObject();
}
This usually works fine. However, when we start this application from another application with ShellExecute() a few items in the treeview will be displayed without any icons at all. It turned out that LoadImage returned a handle although there was no file with the filename strBitmapFile. The invalid Bitmap was then noted by CImageList::Add which returned an index of -1.
Does anybody has an idea whether we are doing something wrong or whether there is a bug in LoadImage? MSDN reported no such bug.
The workaround is quite easy, I check whether the File exists and attempt to load the bitmap just in this case. This works fine, but still one wonders.
Thanks in advance
|
|
|
|