jeudi 5 mars 2015

Constructors in class with only pure virtual functions causes errors in derived classes


I have an abstract class, IPrinter that contains only pure virtual functions.



using namespace std;
class IPrinter
{
public:
virtual void Print() =0;
virtual void Print(string) = 0;
virtual void SetStreamData(string) =0;
private:
IStreamBehavior* streamBehavior;
string _name;
};


And a class that implements it



class HtmlPrinter :
public IPrinter
{
public:
HtmlPrinter();
HtmlPrinter(IPrinter*);
~HtmlPrinter();
virtual void Print();
virtual void Print(string);
vector<string> GetPrintList();
virtual void SetStreamData(string);
private:
IPrinter* printer;
string streamData;
void Paragraph();
};


cpp



HtmlPrinter::HtmlPrinter()
{
}
//error on this line
HtmlPrinter::HtmlPrinter(IPrinter* printer) :printer(printer){}

void HtmlPrinter::Print()
{
this->printer->Print();
}
void HtmlPrinter::Print(string s)
{

}
vector<string> HtmlPrinter::GetPrintList()
{
vector<string> myStrings;
return myStrings;
}
void HtmlPrinter::SetStreamData(string streamData)
{
this->streamData = streamData;
}
HtmlPrinter::~HtmlPrinter()
{
}
void HtmlPrinter::Paragraph()
{
string old = streamData;
streamData += "<p>" + old += "</p>";
}


When I add a constructor or destructor to IPrinter I get an error in the constructor of HtmlPrinter that takes IPrinter*. Why can't I add a constructor/destructor to IPrinter?


Error Message: Error 2 error LNK2019: unresolved external symbol "public: __thiscall



IPrinter::IPrinter(void)" (??0IPrinter@@QAE@XZ) referenced in function "public: __thiscall HtmlPrinter::HtmlPrinter(class IPrinter *)" (??0HtmlPrinter@@QAE@PAVIPrinter@@@Z) C:\Users\darrin\documents\visual studio 2013\Projects\ShapeStore\ShapeStore\HtmlPrinter.obj ShapeStore



Aucun commentaire:

Enregistrer un commentaire