Reputation: 113
i have a class Song that i want to copy...
int mtm::Song::getLimitedLength(int maximum_length) {
Song copied_song(this);
this->Song(copied_song);
}
I get this errors:
Multiple markers at this line
- candidates are:
- no matching function for call to 'mtm::Song::Song(mtm::Song* const)'
Upvotes: 1
Views: 124
Reputation: 43970
Try this:
Song copied_song(*this);
The copy constructor is defined as Song(const Song&)
, but this
is a pointer to Song. Therefore, you need to dereference it.
The line below is somewhat confusing to me:
this->Song(copied_song);
I guess it was only another try to call the copy constructor, wasn't it? Anyway, it doesn't work that way. Use either the solution at the top of my answer, or use:
Song copied_song = *this;
Upvotes: 2
Reputation: 476950
Say Song copied_song(*this);
.
Remember that this
is a pointer, but the copy constructor takes a reference.
Upvotes: 5