c++ - Abstract class and object -
i got first class :
namespace abstract{ class abstractclass{ public: virtual void setname(const std::string & _name) =0; virtual void print() =0; void dynamiccasttest(){}; }; }
and second :
class concreteclass : public abstract::abstractclass{ std::string type; public: concreteclass(); concreteclass(char* a); ~concreteclass(); static concreteclass* createconcreteclass(char* a); virtual void setname(const std::string & _name); virtual void print(); };
but when want define function createconcreteclass(char*):
static concreteclass* createconcreteclass(char* a){ concreteclass a; }
visual cant create object 'a' because tells me it's abstract object.
why ?
i have tried vc10. gives me error c2082 telling me redefinition of formal parameter (i have german installation error message may different). rename variable:
concreteclass* concreteclass::createconcreteclass(char* a) { return new concreteclass(a); }
edit: added static not returning address of temporary
2nd edit: made createconcreteclass static factory function
Comments
Post a Comment