How to create an abstract class in C ++?

1

In C ++ use virtual

.cpp file

#ifndef TETES_H
#define TETES_H


    class Tetes
    {
        public:
            Tetes();
            virtual ~Tetes();
          virtual void exibeDados();
        protected:
        private:
    };

    #endif // TETES_H

.h file

#include "Tetes.h"

Tetes::Tetes()
{
    //ctor
}

Tetes::~Tetes()
{
    //dtor
}

.cpp file

#ifndef TETES1_H
#define TETES1_H


    class Tetes1 : public Testes
    {
        public:
            Tetes1();
            virtual ~Tetes1();
           void exibeDados()
         {
           cout << "Exibe na Tela" << endl; 
          }
        protected:
        private:
    };

    #endif // TETES1_H

.h file

#include "Tetes1.h"

Tetes1::Tetes1()
{
    //ctor
}

Tetes1::~Tetes1()
{
    //dtor
}

... more class teste2 , test3 with the same function but different its contents.

But it gives an error

undefined reference to Testes::exibeDados()

Where do I reference and how? Is this how to define an abstract class in C ++?

    
asked by anonymous 15.03.2016 / 15:41

1 answer

1

I do not know if this is the only problem, but in addition to the names of the files being inverted in the question, the abstract class is called Tetes and then Tetes1 is inherited from Teste . There's already a problem there. Possibly causing others.

Apart from this, it might not be compiling everything on the same compile drive, or linked together, but just seeing the code can not tell.

And it is also necessary to declare the virtual method in the abstract class as without implementation. This is done with = 0 :

virtual void exibeDados() = 0;
    
15.03.2016 / 15:50