473,779 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy objects

pnp
I have two objects AA and AB that derive from object A. These two
objects have common atts that they inherit from object A but also some
of their own.

I have a pointer to an AA object and i would like to turn it to a
pointer to an AB object, but maintaining the common information of these
objects, such as the atts for example.

How can I do this?
Nov 17 '05 #1
6 1737

In the simple form, you can't. If you have a reference to an Apple, you can
change that to a reference to a Pear, even though, as types, they are both
fruit. The further question is why you'd want to do this? Some insight to
your situation could provide us with a clearer understanding of what you're
trying to do.

That said, you could write up a parent copy method that copies the data
member values. This could then be called by a child instance. It's not what
you've asked for, because you'd end up having two obects. AB could be a new
"uninitiali zed" object that calls this method, passing in the reference to
an instance of an AA object. The method simple knows what data members it
can retrieve values from.

"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have two objects AA and AB that derive from object A. These two objects
have common atts that they inherit from object A but also some of their
own.

I have a pointer to an AA object and i would like to turn it to a pointer
to an AB object, but maintaining the common information of these objects,
such as the atts for example.

How can I do this?

Nov 17 '05 #2
Maybe explicit cast operator overloading may help you?

Object AA will implement the cast to AB, and vice versa.

--
Vadym Stetsyak aka Vadmyst
"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:#I******** ******@TK2MSFTN GP12.phx.gbl...
I have two objects AA and AB that derive from object A. These two
objects have common atts that they inherit from object A but also some
of their own.

I have a pointer to an AA object and i would like to turn it to a
pointer to an AB object, but maintaining the common information of these
objects, such as the atts for example.

How can I do this?

Nov 17 '05 #3
pnp
Actually, I have 2 usercontrol objects that derive from the same
usercontrol parent, and what I want to do is change them at runtime from
one type to another depending on what I need to display. e.g. one
holds date values while the other color values...

Dan Bass wrote:
In the simple form, you can't. If you have a reference to an Apple, you can
change that to a reference to a Pear, even though, as types, they are both
fruit. The further question is why you'd want to do this? Some insight to
your situation could provide us with a clearer understanding of what you're
trying to do.

That said, you could write up a parent copy method that copies the data
member values. This could then be called by a child instance. It's not what
you've asked for, because you'd end up having two obects. AB could be a new
"uninitiali zed" object that calls this method, passing in the reference to
an instance of an AA object. The method simple knows what data members it
can retrieve values from.

"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have two objects AA and AB that derive from object A. These two objects
have common atts that they inherit from object A but also some of their
own.

I have a pointer to an AA object and i would like to turn it to a pointer
to an AB object, but maintaining the common information of these objects,
such as the atts for example.

How can I do this?


Nov 17 '05 #4
pnp
Could you please provide an example for this?

Vadym Stetsyak wrote:
Maybe explicit cast operator overloading may help you?

Object AA will implement the cast to AB, and vice versa.

--
Vadym Stetsyak aka Vadmyst
"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:#I******** ******@TK2MSFTN GP12.phx.gbl...
I have two objects AA and AB that derive from object A. These two
objects have common atts that they inherit from object A but also some
of their own.

I have a pointer to an AA object and i would like to turn it to a
pointer to an AB object, but maintaining the common information of these
objects, such as the atts for example.

How can I do this?


Nov 17 '05 #5
using System;
struct Digit
{
byte value;
public Digit(byte value)
{
if (value>9) throw new ArgumentExcepti on();
this.value = value;
}

// define explicit byte-to-Digit conversion operator:
public static explicit operator Digit(byte b)
{
Digit d = new Digit(b);
Console.WriteLi ne("conversion occurred");
return d;
}
}

class Test
{
public static void Main()
{
try
{
byte b = 3;
Digit d = (Digit)b; // explicit conversion
}

catch (Exception e)
{
Console.WriteLi ne("{0} Exception caught.", e);
}
}
}
--
Vadym Stetsyak aka Vadmyst
"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:u$******** ******@TK2MSFTN GP10.phx.gbl...
Could you please provide an example for this?

Vadym Stetsyak wrote:
Maybe explicit cast operator overloading may help you?

Object AA will implement the cast to AB, and vice versa.

--
Vadym Stetsyak aka Vadmyst
"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:#I******** ******@TK2MSFTN GP12.phx.gbl...
I have two objects AA and AB that derive from object A. These two
objects have common atts that they inherit from object A but also some
of their own.

I have a pointer to an AA object and i would like to turn it to a
pointer to an AB object, but maintaining the common information of these
objects, such as the atts for example.

How can I do this?


Nov 17 '05 #6
How do you plan on converting a date to a colour??

"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Actually, I have 2 usercontrol objects that derive from the same
usercontrol parent, and what I want to do is change them at runtime from
one type to another depending on what I need to display. e.g. one holds
date values while the other color values...

Dan Bass wrote:
In the simple form, you can't. If you have a reference to an Apple, you
can change that to a reference to a Pear, even though, as types, they are
both fruit. The further question is why you'd want to do this? Some
insight to your situation could provide us with a clearer understanding
of what you're trying to do.

That said, you could write up a parent copy method that copies the data
member values. This could then be called by a child instance. It's not
what you've asked for, because you'd end up having two obects. AB could
be a new "uninitiali zed" object that calls this method, passing in the
reference to an instance of an AA object. The method simple knows what
data members it can retrieve values from.

"pnp" <pnp.@.softlab. ntua.gr> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have two objects AA and AB that derive from object A. These two objects
have common atts that they inherit from object A but also some of their
own.

I have a pointer to an AA object and i would like to turn it to a pointer
to an AB object, but maintaining the common information of these objects,
such as the atts for example.

How can I do this?



Nov 17 '05 #7

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

Similar topics

42
5808
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same kind. It sounds simple but evidently .NET has difficulty with this concept for some reason. I do understand that .NET objects are created on the GC heap but that doesn't mean that they couldn't be copied from another object of the same kind when...
15
21201
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including pointers) and for objects types call their default constructor. Any others points i should know?
8
2983
by: trying_to_learn | last post by:
Why do we need to explicitly call the copy constructor and the operator = , for base class and member objects in composition? ....book says "You must explicitly call the GameBoard copy-constructor or the default constructor is automatically called instead" Why cant the compiler do this on its own. if we are making an object through copr construction for an inherited class , then why not simply call the corresponding copy constructors for...
5
3288
by: Tony Johansson | last post by:
Hello! I'm reading in a book about C++ and that is something that sound strange. It says "Pointers have reference-assignment semantics similar to those in Java. For example, after the assignment Student* john = michael; both john and michael share the same object. This type of an assignment is different then value-assignmnet semantics used by class variables, as in
16
3143
by: bluekite2000 | last post by:
I want Matrix A(B) to create shallow copy of B but A=B to create deep copy of B. Is that bad design? Why and why not?
4
1440
by: OpticTygre | last post by:
If I pass an object to another form via the new form's tag property, I want to create an object exactly like it, with it's properties and all, but have it be a copy of the object passed through, and not just a reference to the object. Example: Public Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs) Dim obj as Object = Activator.CreateInstance(Me.Tag.GetType())
10
2579
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, we do not need to use the copy-constructor. So depending on the above reasoning I can avoid call by value and return by value for class objects, this bypasses the problem or it seems to me like that. Could any one give me some simple examples...
26
15815
by: saxenavaibhav17 | last post by:
what is Deep Copy, Shallow copy and Bitwise copy, Memberwise copy? and what is the difference between them? pls help vaibhav
13
5022
by: blangela | last post by:
I have decided (see earlier post) to paste my Word doc here so that it will be simpler for people to provide feedback (by directly inserting their comments in the post). I will post it in 3 parts to make it more manageable. Below is a draft of a document that I plan to give to my introductory C++ class. Please note that I have purposely left out any mention of safety issues in the ctors which could be resolved thru some combination...
13
2471
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a certain code syntax but more a 'code architecture' thing , I'll use simple example classes (which are certainly not complete or working...) just to illustrate the idea (and I may make some mistakes because I'm not that experienced...). The...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
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 we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.