s_lavie
asked on
copy classes
Hi,
I want to ask how can I copy a content of one class to another (of the the same type), with no setting a reference.
what I mean is this:
dim a as new myClass
dim b as new myClass
b = a (NOT set b = a)
I want to ask how can I copy a content of one class to another (of the the same type), with no setting a reference.
what I mean is this:
dim a as new myClass
dim b as new myClass
b = a (NOT set b = a)
ASKER
Sorry waty, but this is the naive way to do so, it's not what I meant. What if you have a lots of vars in a class - would you do the same??? It's not realistic.
In C++ you just do a = b or *a = *b. Is there a similar way in VB?
In C++ you just do a = b or *a = *b. Is there a similar way in VB?
Error, in C++ if you do a=b; you copy the adress. So if your class contains pointer, you could go to have some incoherences.
Under C++, you have to construct a copy constructor. In this copy constructor, you copy all the members as you need. It is the same under VB, but you have to call explicitely to the copy function.
Under C++, you have to construct a copy constructor. In this copy constructor, you copy all the members as you need. It is the same under VB, but you have to call explicitely to the copy function.
ASKER
It seems to me that there must be another way, otherwise I wouldn't ask that question.
If you know another way, I would like to know it too.
Drop a mail to Microsoft.
Drop a mail to Microsoft.
dim a as new myClass
dim b as myClass
set b = a
dim b as myClass
set b = a
ASKER
Hi hakyemez,
your answer setes a reference to of the class, but I want a completly different class with the same values, with out any connection, (like in numeric vars).
your answer setes a reference to of the class, but I want a completly different class with the same values, with out any connection, (like in numeric vars).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry Waty,I probably misunderstood the way it works!
So, you could do as follow :
Sub CopyOwnClass(clsDest as myClass)
With clsDest
.A = A
.B = B
End With
End Sub