STOP pass by value for functions defined inside class ( Copyconstructor )

P

Pallav singh

Hi All ,

very basic question
we know that by making copy constructor as private , we cam stop
passing and returning object by value
for a function. But this help us only for function defined Outside
class.

How can i STOP pass by value for functions defined inside class to
pass / return object by value ?

is it possible.

Thanks
Pallav Singh
 
G

gwowen

very basic question
we know that by making copy constructor as private , we cam stop
passing and returning object by value
for a function. But this help us only for function defined Outside
class.
How can i STOP pass by value for functions defined inside class to
pass / return object by value ?

If you need to define a private copy constructor for other purposes,
you can't prevent pass-by-value, except by merely not using it. As
the person who is writing the class, that shouldn't be too onerous.
Otherwise, declare a private copy constructor but don't define it.
Any attempt to pass-by-value will give a link-time error.
 
J

Juha Nieminen

Pallav singh said:
How can i STOP pass by value for functions defined inside class to
pass / return object by value ?

Declare the copy constructor private but leave it unimplemented.
The linker will then tell you if you try to use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top