Undefined reference in C ++

0

I'm studying c ++ and found a problem when working with object orientation, I followed some tutorials but it did not work.

Account.h

#ifndef CONTA_H
#define CONTA_H

#include <string>

using namespace std;

class Conta{

    private:
        string nome;
        int idade;

    public:
        string getNome();
        int getIdade();
};

#endif // CONTA_H

Account.cpp

#include "Conta.h"
#include <string>

using namespace std;

string Conta::getNome(){
    return nome;
}

int Conta::getIdade(){
    return idade;
}

main.cpp

#include <iostream>
#include "Conta.h"

using namespace std;

int main()
{
    Conta p;

    cout << p.getNome() << endl;
    return 0;
}

When I compile the code it brings me this error.

undefined reference to 'Conta::getNome()'

Obs: My Ide is CodeBlocks.

    
asked by anonymous 17.02.2016 / 17:46

1 answer

2

This is not a good way to solve this problem because every time you make a change to the Conta.cpp file, you will need to recompile main.cpp.

It would be best to hit the way you are compiling so that it manages all the necessary objects.

    
17.02.2016 / 18:44