I'm learning C ++, and I have a question about creating classes in different files. I created the header with function prototypes, then as member functions in another cpp file.
When I test the files next to a main I get the following error:
undefined reference to GradeBook::GradeBook(std::string) linha 14
undefined reference to GradeBook::getNomeCurso() linha 16
This is the header with the gradebook class: gradebook.h
#include <iostream>
#include <string>
using namespace std;
class GradeBook
{
public:
GradeBook( string );
void setNomeCurso(string);
string getNomeCurso();
void mostrarMensagem();
private:
string nome_curso;
};
This is the file called gradebook.cpp with member functions in it:
#include <iostream>
#include "gradebook.h"
using namespace std;
GradeBook::GradeBook( string z ){
setNomeCurso(z);
}
void GradeBook::setNomeCurso( string nome ){
nome_curso = nome;
}
string GradeBook::getNomeCurso(){
return nome_curso;
}
void GradeBook::mostrarMensagem(){
cout << "Bem vindo ao Livro de " << getNomeCurso() << "!" << endl;
}
And this is the test.cpp file with the Main function:
#include <iostream>
#include <string>
#include "gradebook.h"
using namespace std;
int main() {
string curso;
cout << "Entre com o nome do curso : ";
getline(cin, curso);
cout << endl;
GradeBook Livro( curso );
cout << "Bem vindo ao curso de " << Livro.getNomeCurso() << endl;
}