Em Java temos a possibilidade de criarmos classes abstratas, mais sem a possibilidade de instanciá-las, porém podemos criar e instanciar uma classe que herde os atributos e os métodos de uma progenitora abstrata. Em C++ isso é feito de uma forma diferente e eu gostaria de saber como se faz?
Até agora eu tentei fazer oque foi dito acima (ou quase), criar uma classe abstrata e herda seu atributos e métodos para outra classe que será instanciável. Segue o código:
Mother.h
#ifndef MOTHER_H_INCLUDED
#define MOTHER_H_INCLUDED
#include <string>
typedef std::string str;
class Mother{
private:
str test01;
str test02;
unsigned test03;
public:
virtual void setTest01(str teste01_)=0;
virtual void setTest02(str teste02_)=0;
virtual void setTest03(unsigned teste03_)=0;
public:
virtual str getTest01()=0;
virtual str getTest02()=0;
virtual unsigned getTest03()=0;
};
#endif // MOTHER_H_INCLUDED
//Red Hat
Mother.cpp
#include "Mother.h"
void Mother::setTest01(str test01_){
test01=test01_;
}
void Mother::setTest02(str test02_){
test02=test02_;
}
void Mother::setTest03(unsigned test03_){
test03=test03_;
}
str Mother::getTest01(){
return test01;
}
str Mother::getTest02(){
return test02;
}
unsigned Mother::getTest03(){
return test03;
}
Daughter.h
#ifndef DAUGHTER_H_INCLUDED
#define DAUGHTER_H_INCLUDED
#include "Mother.h"
class Daughter: virtual public Mother{
};
#endif // DAUGHTER_H_INCLUDED
main.cpp
#include "Mother.h"
#include "Daughter.h"
int main(void){
Daughter tst;
return 0;
}
Quando compilo o programa com o GNU g++:
error: cannot declare variable ‘tst’ to be of abstract type ‘Daughter’ Daughter.h|6|note: because the following virtual functions are pure within ‘Daughter’:|
...entre outros erros e avisos
=0
em cada um deles.