c++ - Abstract functions -


i have little problem exercise. have 2 classes :

the first :

namespace abstract{      class abstractclass{     public:          virtual void setname(const std::string & _name) =0;         virtual void print() =0;         void dynamiccasttest(){};      };  } 

the second :

class concreteclass : public abstract::abstractclass{      std::string type;  public:     concreteclass();     concreteclass(const char* a);     ~concreteclass();      static abstract::abstractclass* createconcreteclass(const char* a);      virtual void setname(const std::string & _name);      virtual void print();   }; 

and cpp file of second class :

#include "concreteclass.h"  concreteclass::concreteclass(){     type = ""; }  concreteclass::concreteclass(const char* a){     type = a; }  concreteclass::~concreteclass(){}  static concreteclass* createconcreteclass(const char* a){     return new concreteclass(a); }  void concreteclass::setname(const std::string & _name){     type = _name; }  void concreteclass::print(){     std::cout<<type<<std::endl; } 

but in main, when call :

const char* s = ""; abstract::abstractclass* = concreteclass::createconcreteclass(s); 

in compilation, visual out me error lnk2019 :

"public: static class concreteclass * __cdecl concreteclass::createconcreteclass(char const *)" (?createconcreteclass@concreteclass@@sapav1@pbd@z)

on last line. why ?

ah, got it:

static concreteclass* createconcreteclass(const char* a){     return new concreteclass(a); } 

is not declaration of:

concreteclass::createconcreteclass(s) 

i'll leave figure out fix is, it's learning experience, , i'm 100% sure don't need practice copy'n'paste - or wait, because i'm sure else post "fixed" answer soon, because don't care if learn or not.

edit: clarify. have declared static member function in class. , have defined static function not member of class.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -