Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have an odd thing going on with a

Status
Not open for further replies.

jstreich

Programmer
Apr 20, 2002
1,067
US
I have an odd thing going on with a defualt copy constructor to a class who's sole private data member is a vector<char> ... For some reason I end up with the first 4 chars being 3 goblygook asccii chars and a space even if the original was valid alpha numaric charictors. The call to the default copy constructor happens when I pass an object by value into a function do some work on it and return by refrence. Any thoughts?
 
I want a copy of it... I got around it by returning by value too. Perhaps I should have passed in by const refrence and called the copy constructor, did the work on the copy and passed out by refrence the new copy. In any case, it compiles and works... A few things I still want to tweak, but this lil' project of mine is pretty much wrapped up. Guess it is on to the next...
 
There are 2 things you might want to do when you pass an
argument to a function:
you want to use a copy of it
or you want the object itself to be changed.
In the first case you should pass it by value,
in the second case its better to pass it by reference.
I found it strange that you wanted to take it in by value
and return it by reference.
Anyway I'm glad it works :) Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
I wanted to make a copy, but because these are relitivly large arrays I'm will be working with, I want to save some time by not copying the data twice, but even with passing by value it seems not to suffer any great time loss.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top