This is a part of a project, so for plagiarism reasons I don't think I can really post my code.
I'm trying to call the constructor of a derived class in my main function, but despite each of the virtual functions being overridden, none of my derived classes will work. I get the following error:
error C2259: 'component' : cannot instantiate abstract class 1> due to following members:
When I changed my virtual function from a pure virtual function to one with an implementation, it was called instead of the over riders.
I've checked everywhere and can't seem to find anyone else with this problem. I know without the full code you might not be able to solve the problem, but any clue about what could cause this problem would be hugely appreciated.
Could it be that the overridden functions are failing to compile?
Thanks for your time guys.
P.S. I can't seem to post the full error as stackoverflow registers it as code, and keeps saying it is not formatted properly.
EDIT: Thanks for your replies
Abstract base class:
class component
{ private: protected: public:
virtual complex<double> getimpedence(double frequency)=0;
virtual double impedencemag(double frequency)=0;
virtual ~component(){cout<<"Calling component destructor..."<<endl;}};
example of a derived class:
class resistor : public component
{ private: protected:
public:
complex<double> impedence;
//Default Constructor
resistor(){impedence.real(0),impedence.imag(0);}
//Parameterised Constructor
resistor(double resistance){impedence.real(resistance),impedence.imag(0); cout<<impedence<<endl;}
//Copy Constructor
resistor(const resistor &resistorin){impedence = resistorin.impedence;}
//Move Constructor
resistor(resistor &&resistorin){impedence = impedence=resistorin.impedence;resistorin.impedence.imag(0),resistorin.impedence.real(0);}
//Return impedence
complex<double> getimpedence(double frequency){return impedence;}
//Return magnitude of impedence
double impedencemag(double frequency){return abs(impedence);}
~resistor(){cout<<"Calling resistor destructor...";}
};
Aucun commentaire:
Enregistrer un commentaire