473,507 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance question: best wrapper for copying base pointer?

Hi folks... I've got a simple inheritance system (base class & 2
derived classes). In essence it looks like this:

class Base { public:
virtual ~Base() { };
virtual void required_function() = 0; };

class Derived1 : public Base { public:
virtual void required_function() { }
int x;};

class Derived2 : public Base { public:
virtual void required_function() { }
int y;};

I want to store Base*'s in another struct, like so:

struct SomeStruct { Base * base; };

I want to write a copy constructor for SomeStruct so that the Base* is
deep-copied. I know there are a bunch of pointer wrappers out there for
doing so (auto_ptr, etc.). What's the simplest one to use for this
purpose?

Thanks,
--Steve (mr************@hotmail.com)

Jun 2 '06 #1
1 1689
mrstephengross wrote:
Hi folks... I've got a simple inheritance system (base class & 2
derived classes). In essence it looks like this:

class Base { public:
virtual ~Base() { };
virtual void required_function() = 0; };

class Derived1 : public Base { public:
virtual void required_function() { }
int x;};

class Derived2 : public Base { public:
virtual void required_function() { }
int y;};

I want to store Base*'s in another struct, like so:

struct SomeStruct { Base * base; };

I want to write a copy constructor for SomeStruct so that the Base* is
deep-copied. I know there are a bunch of pointer wrappers out there for
doing so (auto_ptr, etc.). What's the simplest one to use for this
purpose?


Google for copy_ptr or clone_ptr in this group and in
comp.lang.c++.moderated. You will find that Axter and myself have put code
to illustrate how those pointers can be implemented. You can find more
refined versions of his on www.axter.com.
Best

Kai-Uwe Bux

Jun 2 '06 #2

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

Similar topics

5
2102
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
22
23317
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
9
2296
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new...
6
1654
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
5
3428
by: Scott | last post by:
Hi All, Am I correct in assuming that there is no way to have a base pointer to an object that uses multiple inheritance? For example, class A { /* ... */ }; class B { /* ... */ };
64
3398
by: groups | last post by:
C# is an impressive language...but it seems to have one big limitation that, from a C++ background, seems unacceptable. Here's the problem: I have a third-party Document class. (This means I...
15
7338
by: Anthony Greene | last post by:
This is probably a very introductory object-oriented question, but it has been nagging me for years, and since I've never been able to find the right answer, I've had to work around it with...
2
2573
by: Mahesh | last post by:
Hi, I encounted some problems using GDB with classes that use virtual inheritance. To illustrate this issue, I have created a simple test case. Here it goes. #include <iostream>
2
2604
by: mmcgarry.work | last post by:
Hi, I would like to follow Stroustrup's advice of separating an object interface (abstract class) from an object implementation (concrete class), See Section 15.2.5 in Stroustrup 3rd Edition. ...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.