473,289 Members | 1,808 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,289 software developers and data experts.

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 1682
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
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
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
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
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
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
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
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
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
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. ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.