c++ - What am I not getting about this abstract class implementation? -


PREFACE: I'm relatively inexperienced in C ++ so it can very well be 1 n00b question one day.

I am doing some work whose long term goal is to be portable in many operating systems. I have the following files:

Utilities.

  #include & lt; String & gt; Class utilities {public: utilities () {}; Virtual Utilities () {}; Virtual std :: string ParseString (std :: string const and rawstring) = 0; };  

Utilities Win.h (For Windows Class / Implementation)

  #include & lt; String & gt; #include "Utilities.h" class utilities Win: public utilities {public: Utilities Win () {}; Virtual Utilities () {}; Virtual std :: string ParseString (std :: string const and rawstring); };  

Utilities window

#include & lt; String & gt; #include "UtilitiesWin.h" std :: string UtilitiesWin :: ParseString (std :: string const and rawstring) {// Magic is here! // I will place a line of code to consider it a valid return; }

Then somewhere in my code I have

  #include  

The compiler (Visual Studio 2008) is dying on this instance announcement

  c: \ somepath \ somecode.cpp (3): Error C2259: Utilities': The abstract class can not be instantified due to the following members: 'std :: string utilities: parsstring (constrict :: string and end)' is summarized: \ somepath \ utilities.h (9) : View the 'Utilities: Parsstring' announcement  

So in this matter what I want, the intangible class (utilities) The same use of Trfes and know it to implement version (Utilitivind).

Obviously I am doing something wrong but I am not sure what happened. This happens to me because I am writing that there is probably an important connection between the use of utility adset class for the use of utilities, but I am not sure where I mean the following tasks

  #include & lt; String & gt; #include "UtilitiesWin.h" SomeProgram :: SomeMethod () {Utilities * U = New Utilities (); String Data = U- & gt; Parsstring (stringedata); // stringdata is defined elsewhere) but this means that I will have to go through different versions later (i.e.,  UtilitiesMac () ,  UtilitiesLinux () , Etc.) 

What have I missed here?

utilities * U = new utilities ();

Utilities tells the compiler to create a new instance of the class; The fact is that utility window expands is not necessarily known and does not affect it. There may be a lot of classes that expand the utilities , but you asked those computers to create a new instance of utilities , not the subclass.

It seems that you want to use the factory pattern, which is to create a static method in utilities , which gives a specific example number Utilities: returns:

  static utilities * Utilities: create (zero) {new utilities return ();}  

at some point You must instantize a non-intangible subclass; There is no way to specify useless at that point


Comments