-1

This is my code, I include string only in the header word.h. I don't understand where the problem is.

#ifndef WORD_H
#define WORD_H

#include <string>


class word : public string
{
    private:
         static string valid_ch;
    public:
        word() {}
        word(const string&);
        static word extract(const string&, size_type&);
};

#endif
Appost
  • 329
  • 3
  • 11
  • 1
    https://stackoverflow.com/questions/2034916/is-it-okay-to-inherit-implementation-from-stl-containers-rather-than-delegate – Cory Kramer May 15 '15 at 19:21
  • 2
    Read up on "namespaces" in your favorite C++ reference. – Thomas Matthews May 15 '15 at 19:26
  • 1
    Do you really need a class "word"? Unlike Java and C#, C++ doesn't require that all methods, functions and variables reside in a class. You could have a free standing function to extract a word from a string. – Thomas Matthews May 15 '15 at 19:28
  • 1
    string lives in the std namespace - try std::string - but this does not look like it is going to end well – pete23 May 15 '15 at 19:29
  • 1
    Is not a good practice to derive from `std::string` take a look at this [post](http://stackoverflow.com/questions/6006860/why-should-one-not-derive-from-c-std-string-class) – dlavila May 15 '15 at 19:34
  • I don't program in c++ from 10 years, I know about namespaces, but I simply forgot to write it. It is simply an oversight. maybe it is better if I delete the question – Appost May 15 '15 at 20:22

1 Answers1

2

use std::string instead of string.

Also, std::string is not polymorphic (does not have virtual function for interface and destruction) so word also will not, and cannot be used in place of a string.

Does that match what you are doing?

Emilio Garavaglia
  • 20,229
  • 2
  • 46
  • 63
  • Thank you, I don't program in c++ from 10 years, I found the code on a website on string class. – Appost May 15 '15 at 20:19