Doing a job of assigning names , age , code and note when I try to assign an inheritance to then a set
with AlumnoH
, I get an error. I think it may be the way I'm inheriting it but I really don't have much idea, the error says that a '{'
(yes, sorry, this error was given to me in the void line StudentH::setValue2(string _name, int _age , string _codigo, float _notafinal) : Person(_name, _age){}, right where it says : Person(_name, _age), exactly in the ':') so that it is correct, but I don't think that is the problem. In an example I saw they didn't need that.
If you could recommend me something to review that part, it would be more than great. Thank you!
inheritance.CPP
#include <iostream>
#include <string>
#include "herencia.h"
using namespace std;
Persona::Persona(){}
void Persona::setValue(string _name, int _age){
this-> name = _name;
this-> age = _age;
}
const string Persona::getName() const{
return name;
}
const int Persona::getAge() const{
return age;
}
void AlumnoH::setValue2(string _name, int _age, string _codigo, float _notafinal) : Persona(_name, _age){
this-> codigo = _codigo;
this-> notafinal = _notafinal;
}
Persona::~Persona(){}
inheritance.h
#include <iostream>
#include <string>
using namespace std;
class Persona{
private:
string name;
int age;
public:
Persona();
virtual ~Persona();
Persona(string, int);
virtual ~Persona();
void setValue(string _name, int _age);
const string getName() const;
const int getAge() const;
};
class AlumnoH : public Persona{
private:
string codigo;
float notafinal;
public:
AlumnoH();
virtual ~AlumnoH();
void setValue2(string, int, string, float) : Persona(string, int);
const string getName() const;
const int getAge() const;
const string getCodigo() const;
const float getNotafinal() const;
};
main.cpp
#include <iostream>
#include "herencia.h"
using namespace std;
template<typename T>
void print(T objeto){
cout << objeto.getName() << endl;
cout << objeto.getAge() << endl;
}
int main(){
Persona P1;
P1.setValue("Hernan", 12);
print(P1);
}