|
See the article "Neat things to do in CListCtrl using Custom Draw" on this site by Michael Dunn (sorry i've not given you a link but search and you should get it). Had exactly the same problem and that sorted me out.
-Alex;)
|
|
|
|
|
why virtual destructor?
and what about constructor?
norm
|
|
|
|
|
a virtual destructor ensures that the destructor in the base class is called, in addition to the destructor in any derived classes.
ex:
class A
{
public:
virtual ~A() {...whatver...}
};
class B : public A
{
public:
~B() {...whatver...}
};
when an object of type B is destroyed, both the B destructor and the A destructor will be called.
c++ FAQ lite
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
Thanks, but "both the B destructor and the A destructor will be called."
how did that happen? thru what mechanism is A's destructor invoked when a class B instance is destroy?
i thought, unless:
class B
{
...
...
~B()
{
...
~A(); //Invoke base class destructor?
}
...
...
};
and what about constructor?
norm
|
|
|
|
|
norm wrote:
how did that happen?
it happens automatically as part of C++. you don't have to call A's destructor yourself.
norm wrote:
and what about constructor?
try that link i gave you.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
Chris Losinger wrote:
a virtual destructor ensures that the destructor in the base class is called, in addition to the destructor in any derived classes.
This is only the first part of the statement, because this automatically happens normally. The other half of this statement is when the derived class is used polymorphically in the base class.
So, if you are storing a derived object of type B, in a type A pointer, you will need to have a virtual destructor in the base class A, in order for the proper destructor of class B to be called.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
sheesh - don't do all his homework for him!
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
Chris Losinger wrote:
sheesh - don't do all his homework for him!
Now you make me feel bad for the other more complete post that I made right under the main thread
Actually I just wanted to clarify this fact because it is one of those esoteric things in C++ that it doesn't make that much sense until you actually see it in action. And if you misunderstood the context in which a virtual destructor is useful it might actually cause more confusion.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Paul Watt wrote:
Now you make me feel bad for the other more complete post that I made right under the main thread
Paul Watt wrote:
it is one of those esoteric things in C++ that it doesn't make that much sense until you actually see it in action
yup. i agree.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
You will need to create a virtual destructor if you plan on using your classes polymorphically. However it is good practice to make sure that you always define base classes with virtual destructors to leave that option open for you in the future.
If you create a Derived object B, and store it in a base class pointer A, when you call delete on A for a non-virtual destructor, the destructor for A will be called. However if you declare the destructor virtual, then B's destructor will be called first, and B's destructor automatically calls A's destructor. This memory leak is called slicing.
Here is a small sample program that shows what happens when you have a polymorphically stored derived class in a base class pointer where the base class does not have a virtual destructor.
#include <conio.h>
#include <iostream>
using std::cout;
using std::endl;
class A
{
public:
A ()
{
}
~A()
{
cout << "delete A" << endl;
}
};
class B : public A
{
public:
B () : A()
{
}
~B()
{
cout << "delete B" << endl;
}
};
int main(int argc, char* argv[])
{
B* B_Pointer = new B;
delete B_Pointer;
A* A_Pointer = new B;
delete A_Pointer;
cout << "Press any key to exit" << endl;
::getch();
return 0;
}
This is the output that you will see.
delete B
delete A
delete A
Press any key to exit
The first pointer that is deleted is the object of type B that was stored in a Pointer of type B. Notice how it first calls B's destructor, then A's destructor automatically gets called.
The second object that gets deleted is an object of type B that is stored in an pointer of type A. Only A's destructor will get called.
If you change A's destructor to virtual, this will be the output signifiying that B's destructor properly gets called both times.
delete B
delete A
delete B
delete A
Press any key to exit
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
|
anyone can tell me how to invoke/reference an ATL COM server from an ASP page?
i am pretty new in this subject, but it'd be nice if u can just get me up to speed here and point me in the right direction.
thanks
norm
|
|
|
|
|
As well as a GUID, your component has a friendly name, such as 'Dundas.Chart'. So you do this in your asp
dim oChart
set oChart = CreateObject("Dundas.Chart")
The COOL thing if you have .NET is that it then gives you intellisense on the objects methods ( just found this out ).
If the component is yours, the friendly name is the name written out in the rgs file, if not, it's in the top hive of the registry, and should be in the docs from the vendor.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
sorry, is this VB.NET syntax? I know VB.NET, but not VB and definitely not VBScript.
but it's an ASP (not ASP.NET) application that'll Create this COM object... and i dont get to decide whether we use ASP.NET or ASP.
and i presume this is the code for an in-process COM server?
Thanks!
norm
|
|
|
|
|
is there any good tutorial on how to create an ATL COM server and reference it from ASP web application?
i am rather overwhelmed by all the reading: ATL, MTA/STA, in-process vs out-of-process, local vs remote, registry APIs, interface and MIDL...
norm
|
|
|
|
|
Dammit - just do what I told you to, and it will work. I've written hundreds of lines of classic ASP, calling COM objects that I wrote to do the business logic. Once you call CreateObject, your variable will be an instance of your COM object, and will have (roughly) the same methods as if you called it from C++. I say roughly, it's actually better - a paramter is set and got as if it was a member variable, without the get_ syntax.
The MSDN is full of examples - start by looking up 'CreateObject'.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
This is VBScript syntax, within an ASP or otherwise.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
thanks, just got my ATL-COM-STA local inprocess server runnning and i'm able to consume the service from VC and VB clients.
will try ASP now. havent readup enuf to be sure if an inprocess will be good for our application. i'm still not sure what'd be the threading requirement. just know it will definitely not be DCOM for now.
the application is to generate SQL JOIN logic based on input gathered from an ASP front-end. so, think that many threads will try to access the server at the same time, i think this implies MTA. but i am happy that i can at least get the COM server running and be able to consume the service from ASP for now.
thanks again.
norm
|
|
|
|
|
I've always used this site http://www.learnasp.com/classic/[^] for my ASP problems - pretty much covers everything you'll need.
but like Christian says Server.CreateObject is what you need.
Michael
Life’s not a song.
Life isn’t bliss.
Life is just this.
It’s living. -- Buffy the Vampire Slayer: Once more, with feeling
|
|
|
|
|
I need to retrieve table schema given a table data.
schema information - for a given table - should include:
1. list of columns
2. data type of each column
3. number of records in a table
4. total number of columns
can anyone tell me the API to use for ODBD and ADO to get me up to speed?
Thanks!
norm
|
|
|
|
|
When you use ADO API's to work with database,after you query from that table and fill RecordSet object you can use these methods and properties:
norm wrote:
4. total number of columns
Count property of Fields object.
norm wrote:
1. list of columns
fieldsobject->GetItem(index)->GetName() will return name of EACH column.
norm wrote:
2. data type of each column
fieldsoblect->GetItem(index)->GetType() will do that.
norm wrote:
3. number of records in a table
RecordCount will return number of rows.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
thanks, that's very helpful of u
norm
|
|
|
|
|
How to process the ... in brackets?;P
|
|
|
|
|
How do you mean - that IS how printf is written, isn't it ? CString::Format also works that way, and the source is on your hard drive if you have VC.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
try searching google for va_start, va_arg and va_end.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|