473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

again the problem: the destructor is called twice

Hi all,

I posted my question two days ago, and tried to solve this problem.
but until now I didn't solve that. and I cut my codes so maybe this
time it is more readable.

/////////////////////////////////////////////////////
#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <string>
#include <list>
//#include "name.h"

using namespace std;
class myclass
{
protected:
list<stringnamelist;
// map<int,vector<namenames;
public:

myclass();
myclass(const myclass &my);
~myclass();
// myclass& operator=(const myclass &it);
void AddName(const string &name);
void GetMyclass();
};

#endif

///////////////////////////////////////////////
myclass.cpp
#include "myclass.h"
#include <algorithm>
#include <iostream>

myclass::myclass()
{

}

myclass::myclass(const myclass &my)
{

namelist=my.namelist;
}

myclass::~myclass()
{

namelist.erase(namelist.begin(),namelist.end());
}
void myclass::AddName(const string &name)
{
list<string>::iterator ii;
ii=find(namelist.begin(),namelist.end(),name);

if(ii==namelist.end())
namelist.push_back(name);
}

void myclass::GetMyclass()
{
list<string>::iterator ii;
for(ii=namelist.begin();ii!=namelist.end();ii++)
cout<<*ii<<endl;
}

/////////////////////////////////////////////////
test.h
#ifndef TEST_H_
#define TEST_H_

#include <string>
#include <map>
#include "myclass.h"

using namespace std;

class test
{
protected:
map<string,myclass*tests;

public:
test();
test(const test& mytest);
test& operator=(const test& ts);
~test();
void AddMyclass(const string &name,const myclass &my);
void GetTest();

};

#endif

////////////////////////////////////////////////////
test.cpp

#include "test.h"

#include <utility>
#include <iostream>

test::test()
{
}
test::test(const test& mytest)
{
tests=mytest.tests;
}

test& test::operator =(const test &ts)
{
if(this!=&ts)
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();

tests=ts.tests;
}
return *this;
}

test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();
}
void test::AddMyclass(const string &name,const myclass &my)
{
map<string,myclass*>::iterator ii;
myclass* newmyclass=NULL;

ii=tests.find(name);
if(ii==tests.end())
{
newmyclass=new myclass(my);
tests[name]=newmyclass;
}
}

void test::GetTest()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();ii++)
{
cout<<"the name is:"<<ii->first<<endl;
ii->second->GetMyclass();
}
}

////////////////////////////////////////////////////////////////////
call.h

#ifndef CALL_H_
#define CALL_H_

#include "test.h"

class call
{
public:
inline void SetTest(const test& ts){testagain=ts;}

protected:
test testagain;
};
#endif

///////////////////////////////////////////////////////////////////
main
#include "myclass.h"
#include "test.h"
#include "call.h"

int main()
{
test tt;
myclass my;
string ss[3]={"a","b","c"};
call ca;

for(int i=0;i<3;i++)
my.AddName(ss[i]);

my.GetMyclass();

tt.AddMyclass("my class",my);

tt.GetTest();

ca.SetTest(tt);
return 0;
}

The problem is at the line ca.SetTest(tt). Could somebody tell me how
to solve it? Thanks.

Mar 23 '07 #1
9 3551
On Mar 23, 11:15 am, "David" <clam...@gmail.comwrote:
Hi all,

I posted my question two days ago, and tried to solve this problem.
but until now I didn't solve that. and I cut my codes so maybe this
time it is more readable.

/////////////////////////////////////////////////////
#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <string>
#include <list>
//#include "name.h"

using namespace std;
class myclass
{
protected:
list<stringnamelist;
// map<int,vector<namenames;
public:

myclass();
myclass(const myclass &my);
~myclass();
// myclass& operator=(const myclass &it);
void AddName(const string &name);
void GetMyclass();

};

#endif

///////////////////////////////////////////////
myclass.cpp
#include "myclass.h"
#include <algorithm>
#include <iostream>

myclass::myclass()
{

}

myclass::myclass(const myclass &my)
{

namelist=my.namelist;

}

myclass::~myclass()
{

namelist.erase(namelist.begin(),namelist.end());

}

void myclass::AddName(const string &name)
{
list<string>::iterator ii;
ii=find(namelist.begin(),namelist.end(),name);

if(ii==namelist.end())
namelist.push_back(name);

}

void myclass::GetMyclass()
{
list<string>::iterator ii;
for(ii=namelist.begin();ii!=namelist.end();ii++)
cout<<*ii<<endl;

}

/////////////////////////////////////////////////
test.h
#ifndef TEST_H_
#define TEST_H_

#include <string>
#include <map>
#include "myclass.h"

using namespace std;

class test
{
protected:
map<string,myclass*tests;

public:
test();
test(const test& mytest);
test& operator=(const test& ts);
~test();
void AddMyclass(const string &name,const myclass &my);
void GetTest();

};

#endif

////////////////////////////////////////////////////
test.cpp

#include "test.h"

#include <utility>
#include <iostream>

test::test()
{}

test::test(const test& mytest)
{
tests=mytest.tests;

}

test& test::operator =(const test &ts)
{
if(this!=&ts)
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();

tests=ts.tests;
}
return *this;

}

test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();}

void test::AddMyclass(const string &name,const myclass &my)
{
map<string,myclass*>::iterator ii;
myclass* newmyclass=NULL;

ii=tests.find(name);
if(ii==tests.end())
{
newmyclass=new myclass(my);
tests[name]=newmyclass;
}

}

void test::GetTest()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();ii++)
{
cout<<"the name is:"<<ii->first<<endl;
ii->second->GetMyclass();
}

}

////////////////////////////////////////////////////////////////////
call.h

#ifndef CALL_H_
#define CALL_H_

#include "test.h"

class call
{
public:
inline void SetTest(const test& ts){testagain=ts;}

Here you make a copy of test. There are now two objects in existence,
so two destructors will be called at some point.

>
protected:
test testagain;};

#endif

///////////////////////////////////////////////////////////////////
main
#include "myclass.h"
#include "test.h"
#include "call.h"

int main()
{
test tt;
myclass my;
string ss[3]={"a","b","c"};
call ca;

for(int i=0;i<3;i++)
my.AddName(ss[i]);

my.GetMyclass();

tt.AddMyclass("my class",my);

tt.GetTest();

ca.SetTest(tt);
return 0;

}

The problem is at the line ca.SetTest(tt). Could somebody tell me how
to solve it? Thanks.
You could pass ownership of the test object rather than making a copy.
One way to do that is to use std::auto_ptr, which signifies unique
ownership. So if your "call" class accepts an auto_ptr<test>, the
implicit understanding is that it takes sole ownership of that object.

Cheers! --M

Mar 23 '07 #2
"David" <cl*****@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
Hi all,

I posted my question two days ago, and tried to solve this problem.
but until now I didn't solve that. and I cut my codes so maybe this
time it is more readable.

/////////////////////////////////////////////////////
#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <string>
#include <list>
//#include "name.h"

using namespace std;
class myclass
{
protected:
list<stringnamelist;
// map<int,vector<namenames;
public:

myclass();
myclass(const myclass &my);
~myclass();
// myclass& operator=(const myclass &it);
void AddName(const string &name);
void GetMyclass();
};

#endif

///////////////////////////////////////////////
myclass.cpp
#include "myclass.h"
#include <algorithm>
#include <iostream>

myclass::myclass()
{

}

myclass::myclass(const myclass &my)
{

namelist=my.namelist;
}

myclass::~myclass()
{

namelist.erase(namelist.begin(),namelist.end());
}
void myclass::AddName(const string &name)
{
list<string>::iterator ii;
ii=find(namelist.begin(),namelist.end(),name);

if(ii==namelist.end())
namelist.push_back(name);
}

void myclass::GetMyclass()
{
list<string>::iterator ii;
for(ii=namelist.begin();ii!=namelist.end();ii++)
cout<<*ii<<endl;
}

/////////////////////////////////////////////////
test.h
#ifndef TEST_H_
#define TEST_H_

#include <string>
#include <map>
#include "myclass.h"

using namespace std;

class test
{
protected:
map<string,myclass*tests;

public:
test();
test(const test& mytest);
test& operator=(const test& ts);
~test();
void AddMyclass(const string &name,const myclass &my);
void GetTest();

};

#endif

////////////////////////////////////////////////////
test.cpp

#include "test.h"

#include <utility>
#include <iostream>

test::test()
{
}
test::test(const test& mytest)
{
tests=mytest.tests;
}
Above is your copy constructor. Yet you have a map of pointers you are not
copying correctly. Remember, your test destructor will delete the pointers,
and generally I've found that when a copy constructor is called there is a
temporary made somewhere that needs to be deleted. Pointers moving from
class to class is a bad idea where there is a delete. Generally what you
have to do is duplicate the objects the pointers are pointing to. new a new
pointer, assign the value so that when the old one gets deleted you don't
lose the data.

If I have a class that has pointers to newed objects, I always make the copy
and assignment operators private so they can't be called. Unless you work
with smart pointers you'll have issues.

Think about your line later:
ca.SetTest(tt);
ca is to have a map of the ponters, but so is tt. Yet you only newed them
once. You have 2 different objects (attempting to) point to the same
memory, but they get deleted. If you have 2 objects with pointers, for an
assignment or copy you have to copy the objects the memory is pointing to so
you have 2 seperate memories they are pointing to and their deletes work
correctly, or you have to think very very carefully about object ownership.
After cs.SetTest(tt) who do you expect to "own" the memory the pointers are
pointing to? You can't have 2 seperate instances owning the same pointers.
Unless you use smart pointers of some type.

You have a design flaw here and you are going to have to rethink your
classes.
test& test::operator =(const test &ts)
{
if(this!=&ts)
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();

tests=ts.tests;
}
return *this;
}

test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();
}
void test::AddMyclass(const string &name,const myclass &my)
{
map<string,myclass*>::iterator ii;
myclass* newmyclass=NULL;

ii=tests.find(name);
if(ii==tests.end())
{
newmyclass=new myclass(my);
tests[name]=newmyclass;
}
}

void test::GetTest()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();ii++)
{
cout<<"the name is:"<<ii->first<<endl;
ii->second->GetMyclass();
}
}

////////////////////////////////////////////////////////////////////
call.h

#ifndef CALL_H_
#define CALL_H_

#include "test.h"

class call
{
public:
inline void SetTest(const test& ts){testagain=ts;}

protected:
test testagain;
};
#endif

///////////////////////////////////////////////////////////////////
main
#include "myclass.h"
#include "test.h"
#include "call.h"

int main()
{
test tt;
myclass my;
string ss[3]={"a","b","c"};
call ca;

for(int i=0;i<3;i++)
my.AddName(ss[i]);

my.GetMyclass();

tt.AddMyclass("my class",my);

tt.GetTest();

ca.SetTest(tt);
return 0;
}

The problem is at the line ca.SetTest(tt). Could somebody tell me how
to solve it? Thanks.

Mar 23 '07 #3
On 23 Mar 2007 08:23:01 -0700, "mlimber" wrote:
>On Mar 23, 11:15 am, "David" <clam...@gmail.comwrote:
>>
int main()
{
test tt;
myclass my;
string ss[3]={"a","b","c"};
call ca;

for(int i=0;i<3;i++)
my.AddName(ss[i]);

my.GetMyclass();

tt.AddMyclass("my class",my);

tt.GetTest();

ca.SetTest(tt);
return 0;

}

The problem is at the line ca.SetTest(tt). Could somebody tell me how
to solve it? Thanks.

You could pass ownership of the test object rather than making a copy.
One way to do that is to use std::auto_ptr, which signifies unique
ownership. So if your "call" class accepts an auto_ptr<test>, the
implicit understanding is that it takes sole ownership of that object.
Goodness gracious! tt is a local automatic object. No need to "pass
ownership" or use a 'smart pointer'. Better make the copy constructor
and operator= for all classes private (leave them un-implemented) and
your code will work with some changes.

Best regards,
Roland Pibinger
Mar 23 '07 #4
David wrote:
Hi all,

I posted my question two days ago, and tried to solve this problem.
but until now I didn't solve that. and I cut my codes so maybe this
time it is more readable.

/////////////////////////////////////////////////////
#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <string>
#include <list>
//#include "name.h"

using namespace std;
class myclass
{
protected:
list<stringnamelist;
// map<int,vector<namenames;
public:

myclass();
myclass(const myclass &my);
~myclass();
// myclass& operator=(const myclass &it);
void AddName(const string &name);
void GetMyclass();
};

#endif

///////////////////////////////////////////////
myclass.cpp
#include "myclass.h"
#include <algorithm>
#include <iostream>

myclass::myclass()
{

}

myclass::myclass(const myclass &my)
{

namelist=my.namelist;
}

myclass::~myclass()
{

namelist.erase(namelist.begin(),namelist.end());
}
void myclass::AddName(const string &name)
{
list<string>::iterator ii;
ii=find(namelist.begin(),namelist.end(),name);

if(ii==namelist.end())
namelist.push_back(name);
}

void myclass::GetMyclass()
{
list<string>::iterator ii;
for(ii=namelist.begin();ii!=namelist.end();ii++)
cout<<*ii<<endl;
}

/////////////////////////////////////////////////
test.h
#ifndef TEST_H_
#define TEST_H_

#include <string>
#include <map>
#include "myclass.h"

using namespace std;

class test
{
protected:
map<string,myclass*tests;

public:
test();
test(const test& mytest);
test& operator=(const test& ts);
~test();
void AddMyclass(const string &name,const myclass &my);
void GetTest();

};

#endif

////////////////////////////////////////////////////
test.cpp

#include "test.h"

#include <utility>
#include <iostream>

test::test()
{
}
test::test(const test& mytest)
{
tests=mytest.tests;
}

test& test::operator =(const test &ts)
{
if(this!=&ts)
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();

tests=ts.tests;
}
return *this;
}

test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
delete(ii->second);
tests.clear();
}
void test::AddMyclass(const string &name,const myclass &my)
{
map<string,myclass*>::iterator ii;
myclass* newmyclass=NULL;

ii=tests.find(name);
if(ii==tests.end())
{
newmyclass=new myclass(my);
tests[name]=newmyclass;
}
}

void test::GetTest()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();ii++)
{
cout<<"the name is:"<<ii->first<<endl;
ii->second->GetMyclass();
}
}

////////////////////////////////////////////////////////////////////
call.h

#ifndef CALL_H_
#define CALL_H_

#include "test.h"

class call
{
public:
inline void SetTest(const test& ts){testagain=ts;}

protected:
test testagain;
};
#endif

///////////////////////////////////////////////////////////////////
main
#include "myclass.h"
#include "test.h"
#include "call.h"

int main()
{
test tt;
myclass my;
string ss[3]={"a","b","c"};
call ca;

for(int i=0;i<3;i++)
my.AddName(ss[i]);

my.GetMyclass();

tt.AddMyclass("my class",my);

tt.GetTest();

ca.SetTest(tt);
return 0;
}

The problem is at the line ca.SetTest(tt). Could somebody tell me how
to solve it? Thanks.
Your copy constructor hints a shallow copy while your copy assignment
operator hints a deep copy. You are contradicting youself in terms of
exactly what you want to do with the private data in test class.

Fei
Mar 23 '07 #5
On Mar 23, 11:57 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
On 23 Mar 2007 08:23:01 -0700, "mlimber" wrote:
You could pass ownership of the test object rather than making a copy.
One way to do that is to use std::auto_ptr, which signifies unique
ownership. So if your "call" class accepts an auto_ptr<test>, the
implicit understanding is that it takes sole ownership of that object.

Goodness gracious! tt is a local automatic object. No need to "pass
ownership" or use a 'smart pointer'. Better make the copy constructor
and operator= for all classes private (leave them un-implemented) and
your code will work with some changes.
Like I said, there are multiple ways to accomplish this, and passing
ownership like I described is one common and useful way to do it.
Compare this FAQ by the Creator on using auto_ptr to pass ownership:

http://www.research.att.com/~bs/bs_f...l#memory-leaks

Of course, the "Big Three" (or probably better, the "Big Two" --
http://www.artima.com/cppsource/bigtwo.html) problems ought to be
fixed in any case.

Cheers! --M

Mar 23 '07 #6
On Mar 23, 3:10 pm, "mlimber" <mlim...@gmail.comwrote:
On Mar 23, 11:57 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
On 23 Mar 2007 08:23:01 -0700, "mlimber" wrote:
>You could pass ownership of the test object rather than making a copy.
>One way to do that is to use std::auto_ptr, which signifies unique
>ownership. So if your "call" class accepts an auto_ptr<test>, the
>implicit understanding is that it takes sole ownership of that object.
Goodness gracious! tt is a local automatic object. No need to "pass
ownership" or use a 'smart pointer'. Better make the copy constructor
and operator= for all classes private (leave them un-implemented) and
your code will work with some changes.

Like I said, there are multiple ways to accomplish this, and passing
ownership like I described is one common and useful way to do it.
Compare this FAQ by the Creator on using auto_ptr to pass ownership:

http://www.research.att.com/~bs/bs_f...l#memory-leaks

Of course, the "Big Three" (or probably better, the "Big Two" --http://www.artima.com/cppsource/bigtwo.html) problems ought to be
fixed in any case.

Cheers! --M
Thanks all for your help. I think I need a "deep copy" in my
copyconstructor. sorry I am new in C++, so when I tried to do below,
there was something wrong with this:
test::test(const test& mytest)
{

map<string,myclass*>::iterator ii;

for(ii=mytest.tests.begin();ii!=mytest.tests.end() ;++ii)
{
myclass* my=new myclass;
memcpy(my,ii->second,sizeof(ii->second));
tests.insert(make_pair(ii->first,my));
}
}

there was an error: "c:\Ug\Solution1\test\test.cpp(16): error C2679:
binary '=' : no operator found which takes a right-hand operand of
type 'std::_Tree<_Traits>::const_iterator' " at the for loop point.
can anybody tell me why and what's the right way to do the copy
constructor? thanks

Mar 23 '07 #7
"David" <cl*****@gmail.comwrote in message
news:11**********************@l75g2000hse.googlegr oups.com...
On Mar 23, 3:10 pm, "mlimber" <mlim...@gmail.comwrote:
>On Mar 23, 11:57 am, rpbg...@yahoo.com (Roland Pibinger) wrote:
On 23 Mar 2007 08:23:01 -0700, "mlimber" wrote:
You could pass ownership of the test object rather than making a copy.
One way to do that is to use std::auto_ptr, which signifies unique
ownership. So if your "call" class accepts an auto_ptr<test>, the
implicit understanding is that it takes sole ownership of that object.
Goodness gracious! tt is a local automatic object. No need to "pass
ownership" or use a 'smart pointer'. Better make the copy constructor
and operator= for all classes private (leave them un-implemented) and
your code will work with some changes.

Like I said, there are multiple ways to accomplish this, and passing
ownership like I described is one common and useful way to do it.
Compare this FAQ by the Creator on using auto_ptr to pass ownership:

http://www.research.att.com/~bs/bs_f...l#memory-leaks

Of course, the "Big Three" (or probably better, the "Big
Two" --http://www.artima.com/cppsource/bigtwo.html) problems ought to be
fixed in any case.

Cheers! --M

Thanks all for your help. I think I need a "deep copy" in my
copyconstructor. sorry I am new in C++, so when I tried to do below,
there was something wrong with this:
test::test(const test& mytest)
{

map<string,myclass*>::iterator ii;

for(ii=mytest.tests.begin();ii!=mytest.tests.end() ;++ii)
{
myclass* my=new myclass;
memcpy(my,ii->second,sizeof(ii->second));
tests.insert(make_pair(ii->first,my));
}
}

there was an error: "c:\Ug\Solution1\test\test.cpp(16): error C2679:
binary '=' : no operator found which takes a right-hand operand of
type 'std::_Tree<_Traits>::const_iterator' " at the for loop point.
can anybody tell me why and what's the right way to do the copy
constructor? thanks
The parameter to the copy constructor is a const test& mytest. mytest is
constant. You are trying to use a non-constant iterator on it, which isn't
allowed.
Try:

map<string,myclass*>::const_iterator ii;
Mar 23 '07 #8
On Mar 23, 3:26 pm, "David" <clam...@gmail.comwrote:
On Mar 23, 3:10 pm, "mlimber" <mlim...@gmail.comwrote:
Of course, the "Big Three" (or probably better, the "Big Two" --http://www.artima.com/cppsource/bigtwo.html) problems ought to be
fixed in any case.

Thanks all for your help. I think I need a "deep copy" in my
copyconstructor. sorry I am new in C++, so when I tried to do below,
there was something wrong with this:
test::test(const test& mytest)
{

map<string,myclass*>::iterator ii;
You need

map<string,myclass*>::const_iterator ii;

since mytest is const.
>
for(ii=mytest.tests.begin();ii!=mytest.tests.end() ;++ii)
{
myclass* my=new myclass;
memcpy(my,ii->second,sizeof(ii->second));
tests.insert(make_pair(ii->first,my));
}

}

there was an error: "c:\Ug\Solution1\test\test.cpp(16): error C2679:
binary '=' : no operator found which takes a right-hand operand of
type 'std::_Tree<_Traits>::const_iterator' " at the for loop point.
can anybody tell me why and what's the right way to do the copy
constructor? thanks
Read the article on the law of the Big Two that I gave in my previous
post.

Here's a tip: If you see memcpy in C++ code, that's bad (usually).
Prefer to give myclass proper copy semantics so you can say:

*my = *( ii->second );

Better still would be to use a smart pointer that does -- depending on
your needs -- either reference counting (e.g., std::tr1::shared_ptr,
boost::shared_ptr, Loki::SmartPtr, or the one in FAQ 16.22 and
following) or deep copying (e.g., Loki::SmartPtr) for you
automatically.

Cheers! --M

Mar 23 '07 #9
On 23 Mar 2007 12:26:52 -0700, "David" <cl*****@gmail.comwrote:
>I think I need a "deep copy" in my copyconstructor.
You need no copy constructor at all. You can and, IMO, should
implement your library with disabled (= private) copy constructors and
assignmet operators. There is no need to duplicate and dynamically
allocate objects.

Best wishes,
Roland Pibinger
Mar 23 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alexander Stippler | last post by:
Hi, I have some question about the usage of delete. I have some reference counted classes, all derived from SharedObject. It's destructor looks like this: ~SharedObject() { if...
52
by: Newsnet Customer | last post by:
Hi, Statement 1: "A dynamically created local object will call it's destructor method when it goes out of scope when a procedure returms" Agree. Statement 2: "A dynamically created object...
9
by: sahukar praveen | last post by:
Hello, This is the program that I am trying. The program executes but does not give me a desired output. ********************************************** #include <iostream.h> #include...
20
by: frs | last post by:
For memory economization, I need to get rid if the virtual destructor. Under this constraint I get caught up in a design, where I need to call a destructor of a derived class from a base class....
14
by: gurry | last post by:
Suppose there's a class A. There's another class called B which looks like this: class B { private: A a; public : B() { a.~A() } }
2
by: Kuku | last post by:
#include<iostream> using namespace std; class Mammal { private: int age, weight;
11
by: AB | last post by:
Hi All, I've got an array of objects, during the execution of the program I'd like to assign a particular object to a certain element in the object array. The sample code's like this... class...
4
by: David | last post by:
Hi all, something wrong with my code, it seems that the destructor function has been called twice. I don't know why.here is my codes Fixture.h #ifndef _FIXTURE_H #define _FIXTURE_H #include...
12
by: mc | last post by:
Hi Experts, This may be obvious but I can't find anything one way or another. We have a class which is always allocated using new, e.g. Foo* foo = new Foo() so we came up with the idea of...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.