0
I’m studying c++ and found a problem when working with object orientation, I followed some tutorials but it didn’t work.
Bill. 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
Cpp account.
#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()'
Note: my ide is Codeblocks.
Probably not compiling the
Conta.cpp
along.– Maniero
i did a include on my main.cpp ( #include "Account.cpp" ) it worked, but doing it is good practice or is wrong?
– Kaio Fernandes
Don’t do this. Working doesn’t mean it’s right.
– Maniero
Thanks bigown, the problem was at compilation time same, I installed the dev c++ and ran first.
– Kaio Fernandes
Now you have an extra problem :D
– Maniero
but I won’t use it no :) I’m testing other compilers
– Kaio Fernandes