|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi Everyone,
It is possible to pass a structure to a function by value in c just like how class is being passed to functions by value in c++. c++ introduces the copy constructor for this very purpose of making sure deep copy is performed on c++ objects which have pointers pointing to some memory location. It is very much possible to have a c structure having a pointer, how does c solve the problem? making sure deep copy is done? Thanks in advance!!! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Rahul wrote:
> Hi Everyone, > > It is possible to pass a structure to a function by value in c just > like how class is being passed to functions by value in c++. > c++ introduces the copy constructor for this very purpose of making > sure deep copy is performed on c++ objects which have pointers > pointing to some memory location. > > It is very much possible to have a c structure having a pointer, how > does c solve the problem? making sure deep copy is done? > It doesn't, you get a shallow copy. Why would you want to pass such a structure by value? -- Ian Collins. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Rahul said:
> Hi Everyone, > > It is possible to pass a structure to a function by value in c just > like how class is being passed to functions by value in c++. > c++ introduces the copy constructor for this very purpose of making > sure deep copy is performed on c++ objects which have pointers > pointing to some memory location. > > It is very much possible to have a c structure having a pointer, how > does c solve the problem? making sure deep copy is done? C doesn't solve the problem. C assumes you know how to solve the problem. (It's not difficult. Step 1: write a "copy constructor" function. Step 2: call it to create a copy. Step 3: use the copy. Step 4: destroy the copy when you're done with it.) -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
![]() |
| Outils de la discussion | |
|
|