"error: 'string' does not name a type" when declaring strings

2

Follow the code

class Nome
{
    public:
        Nome(string nome, string sobreNome);
        void exibirNome();
        virtual ~Nome();
    protected:
    private:
         string nome;
         string sobreNome;

};

Error

  

error: expected ')' before 'name'

     

error: 'string' does not name a type

     

error: 'string' does not name a type

    
asked by anonymous 27.03.2016 / 13:54

1 answer

4

You must include the string header. And the full name of the type would be std::string , so a using is usually appropriate so you do not have to describe the namespace every time. In C ++ the grouping of the names is separated from the grouping of the codes ( header files).

I've reorganized to avoid redundant code and become more idiomatic.

#include <string>
using namespace std;

class Nome {
        string nome;
        string sobreNome;
    public:
        Nome(string nome, string sobreNome);
        void exibirNome();
        virtual ~Nome(); //espero que vá usar, senão não tem porque criar isto
};

See running on ideone .

    
27.03.2016 / 14:04