C2H50H C2H50H - 1 month ago 6
C++ Question

'No matching function call too'

I'm doing a problem where I have my base class: track. My class: disc inherits from it so I believe it is trying to call the default constructor from the track class. However I was specifically told to delete the track default constructor and only use one with parameters. I keep getting error when my disc class constructor is compiled.

Error:

/home/csugrads/wilse016/cs1521/projects/project5/disc.cpp:10:12: error: use of deleted function ‘track::track()’
disc::disc(){
^


Disc Constructor

disc::disc(){
//Create trackListPtr to an empty list

std::unique_ptr<LinkedList<std::shared_ptr<track>>> trackListPtr;
}


track.h

#ifndef _TRACK
#define _TRACK

#include <memory>
#include "LinkedList.h"

class disc;

class track{

private:

std::string tName;


std::string tArtist;


int playTime;


int trackNumber;


std::string location;


std::shared_ptr<LinkedList<track>> trackListPtr;


public:
track() = delete;

track(disc* discP);


void readTrack();


const void printTrack();


const bool isLessThan(track aTrack);


const int getNumber();


const int getPlayTime();


};
#endif


Please let me know if there is any other files you need to see. Do I need to be passing an argument somewhere in my disc constructor? Thanks!

Answer

Try:

disc::disc() :  track(nullptr){
    //Create trackListPtr to an empty list
    std::unique_ptr<LinkedList<std::shared_ptr<track>>> trackListPtr;
}

So your disc class will use track's constructor with parameter instead of default one.