[LC++]Question about ctors and dtors
Paul M Foster
paulf at quillandmouse.com
Tue Apr 2 17:30:18 UTC 2002
See the following code. When run, the output is only for the test()
member. There is no output for the ctor and dtor. Why? Surely an object
of the bogus class is being created?
Paul
================================ code ============================
#include <vector>
class bogus
{
private:
int x;
public:
bogus();
~bogus();
void test();
};
bogus::bogus()
{
cout << "constructing bogus" << endl;
}
bogus::~bogus()
{
cout << "deconstructing bogus" << endl;
}
void bogus::test()
{
cout << "this is a test of bogus" << endl;
}
int main()
{
vector<bogus> mv;
mv[0].test();
return 0;
}
More information about the tuxCPProgramming
mailing list