|
|
|
Hi
I need to ensure that an object of a one of my classes only gets created on the stack as opposed to on the heap using 'new'. Is there a compiler keyword (I'm using VC .net)
or some other method to ensure this.
Thanks
Garf
|
|
|
|
|
I'm not a guru, so take this as a SWAG:
Maybe you could override operator new for your class, and let it throw an exception if invoked?
Or did you mean that operator new should allocate the object on the stack instead of the heap?, in that case, I would say: Not recommendable. (And probably very hard to implement).
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Thanks Jan
I should have mentioned that I was actually looking for a compile time solution.
Serqe's solution seems to be what I was looking for.
Garth
|
|
|
|
|
you need to declare the operator new as either a private or protected; for example:
class A
{
private:
void* operator new(size_t);
};
int _tmain(int argc, _TCHAR* argv[])
{
//error C2248: 'A::operator new' : cannot access private member declared in class 'A'
A* pA = new A;
// OK
A a;
return 0;
}
|
|
|
|
|
Thanks Serge
This is exactly what I was looking for.
Garth
|
|
|
|
|
thanks for you time first,,
i would like to write a video codec filter, which can be plugged into Windows Media Player
(which means media player chooses my codec filter and play) automatically
when someone clicks my codec aware media file.
but i dont know where to start/ look first,
any advice would be very appreciated.
thanks
|
|
|
|
|
try to look into DirectX's SDK samples, maybe there are some filter examples
rrrado
|
|
|
|
|
Hello all,
Visual SourceSafe has long been a popular choice for source code control and file management purposes. As collaborative team becomes a prevailing form, it is common now to have members from different geographic location sharing source code and other files when working on a project.
SourceSafe is designed for project teams on local network, this is why we need a tool enabling each member to easily connect to VSS database from anywhere with internet using.
Software purchasing, unlike selecting other IT commodities, will arouse non-retrievable loss in case the potential bugs of a product. So reliability should be regarded as the primary request for a SCC tool.
With several years of experience in this domain, I'd like to help you with some good suggestions as I can if you meet any SCC problem and you trust me.
Anyway, leave me a message.
Regards!
sourceanywhere
from http://www.dynamsoft.com/SAWPro_Overview.html
|
|
|
|
|
Now, listen very carefully webcrap, because I will say this only once: this is NOT the place to advertise. If you want to advertise, you can support CP by buying banner space.
If you'd care to step into the Soapbox, I will happily provide you with the facts as to where you can apply your product.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
As in, "fold it until it's all sharp corners, and ..."
Software Zen: delete this;
|
|
|
|
|
Hello,
I want to know when windows is not doing any work,
Please help me on this.
Thanks.
|
|
|
|
|
What windows?
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
I think OnIdle Member Function will help u.
|
|
|
|
|
Windows is never idle, per se. It's always doing something, even in the OnIdle() handler. The default implementation updates menu items and toolbar buttons, and it performs internal data structure cleanup.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hi,
I have a MFC application. when I compiled as 'Win32 Debug with MFC dll' it works fine, but when I compiled it as 'Win32 Release with MFC dll' I encountered an error:
the instruction at 0x77fc8f11 referenced memory at 0x9486f4f8. the memory could not be "written".
It occured every time I call a specific function from some dll that I load into the project, but not always in the same place (i.e. I might do some different actions in my application that will lead to this).
I stand a bit clueless here.
any help will be appriciated.
thanks,
Yaron.
|
|
|
|
|
|
Hi,
I have a general question on constructors in C++. If my constructor throws an exception is the object created? If so, is it a valid object? Can I invoke the methods of the class using that object?
How should you handle this scenario?
Thanks,
Mel
|
|
|
|
|
May be the answer can change depending on compiler, but as far as I know, the constructor is called after memory allocation has occurred and its first instructions (think as executed at the "open brace") are "call the bases constructors and call the members constructors".
At that point the object can be assumed as effectively constructed and formed.
The problem is another: if your object is used as a base of another object and your constructor throws an exception ... The "other" object is not properly constructed. But the memory is allocated.
But the other object constructor cannot handle the exception as well, since it didn’t reach any possible "try/catch" block. (It escaped from its open brace)
In fact your exception escapes the constructors leaving the instantiator (the piece of program that asked to create the outer object) with an allocated, but partially constructed object.
The fact that "delete" can be properly called by the calling program, mostly depend on what constructors and destructors do.
Moral: avoid to throw exceptions in constructors... a "two phase construction" (by calling a separate "init" function after the construction) can be safer and give a more predictable behaviour.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
No, the object is not created if the constructor throws an exception. See GotW #66[^] for a detailed discussion of the subject.
|
|
|
|
|
The C++ standard says that if a constructor throws an exception any memory allocated will be freed, but no destructor will be called. It is not a valid object and you cannot invoke members. If you try to do so the behaviour is undefined. In C++, undefined usually means it will crash.
I'm pretty sure that VC++ implements this behaviour correctly. In essence it wraps a new operation in a try /catch block and calls ::operator delete (or the class's operator delete , if it or a base class implements one), if C++ exception handling is enabled.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Dear Everybody,
I want to make my application can get a file name when i hook mouse at a known position.I have a idea that write a shell dll that capture file name when a mouse click event happened, then put file name to a shared memory with my application.Is is possible?If anyone show me other way to do, I would very appriciated.
Thank you in advanced.
|
|
|
|
|
In a dialog form there are three three edit boxes which and button.
The member variable of three edit boxes are of integer types.The three edit boxes represent the RGB color.Suppose if I click the button which on the form background color of the dialog form should according to the value entered the three edit boxes which are present on the dialog form.
The changing of the background color is given below
HBRUSH CBackColor1Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if( pWnd == this)
{
pDC->SetTextColor(RGB(100, 255, 111));
pDC->SetBkColor(RGB(255, 255, 255));
hbr = (HBRUSH)(m_pBlackBkBrush->GetSafeHandle());
}
return hbr;
}
The code for the button control is given below
void CBackColor1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
}
Can any one please tell how to integrate OnCtlColor member function with onButton1() member function .
Philip
|
|
|
|
|
if(pWnd->GetDlgCtrlID() == IDC_BUTTON1)
{
}
Found on Bash.org
I'm going to become rich and famous after i invent a device that allows you to stab people in the face over the internet
My Articles
|
|
|
|