Re: Overcoming C# limitations

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Nothing is hidden here. Every object's destructor is called when it
leaves scope. You might as well have defined a CString and have a
"hidden" destructor as you call it run when the function leaves. It's a
very simple design concept of programing in C++. I'm not debating
wether C# has done a better job, I'm sure it has. I was just asking if
I could somehow mimic some C++ features that in my opinion, make things
a bit easier to do.


james.curran@xxxxxxxxx wrote:
Danny Liberty wrote:
2. In C++ I could have defined a macro to instantiate an object and
then make a method call. For example:
#define MY_FUNC(x) MyObj a; a.func(x);
This would have been useful since I could use this macro in any scope
knowing that the destructor of MyObj (or instance a) will be called at
the end of the scope without explictly calling any function. For
example:
void Foo()
{
MY_FUNC(3);
.... more code....
} <-- destructor of MyObj would be called here


um... You want to hid the call to the ctor, and then have significant
action in the dtor. Forgive me, but I'm really glad I don't have to
maintain your code....

.



Relevant Pages

  • Re: Object destruction
    ... MyObject * myObj; ... myObject is destroyed when it goes out of scope in main. ... destructor (or, in a sense, it has a trivial destructor that does ...
    (microsoft.public.vc.language)
  • Re: Object destruction
    ... MyObject * myObj; ... myObject is destroyed when it goes out of scope in main. ... destructor (or, in a sense, it has a trivial destructor that does ...
    (microsoft.public.vc.language)
  • Re: Overcoming C# limitations
    ... leaves scope. ... You might as well have defined a CString and have a ... "hidden" destructor as you call it run when the function leaves. ... Michael ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Returning address of local variable
    ... real-world hardware) to unmap the memory when the variable ... out of scope, the whole concept of destruction is absent from plain C. ... destructor, when a auto storage variable of that type goes out of scope ...
    (comp.lang.c)
  • Re: Life of a thread
    ... > If a thread goes out of scope and the working proc is done ... Unless, of course, you have unmanaged resources (like a database ... IDisposable and add a ~Destructor to handle all unmanaged ...
    (microsoft.public.dotnet.languages.csharp)