Enviado em 24/06/2013 - 20:13h
Bom, estou começando a programar em c++ e fui criar algumas classes, separadas, mais diacho do compilador manda um erro, que não faço a minima idéia que seja, se eu coloco tudo em um arquivo .cpp ele roda, mas se crio arquivos, .cpp , .hpp/.h .cpp não compila , um código bem simplespessoa.hpp #ifndef PESSOA_H #define PESSOA_H #include <iostream> #include <string> using namespace std; class Pessoa{ int idade; string nome; public: Pessoa(); Pessoa(int idade, string nome); int getIdade(); void setIdade(int idade); string getNome(); void setNome(string nome); }; #endif
pessoa.cpp #include "pessoa.hpp" #include <iostream> using namespace std; #include <string> Pessoa::Pessoa(){ idade=0; nome=""; } Pessoa::Pessoa(int idade, string nome){ this->idade=idade; this->nome=nome; } void Pessoa::setIdade(int idade){ this->idade=idade; } int Pessoa::getIdade(){ return idade; } void Pessoa::setNome(string nome){ this->nome=nome; } string Pessoa::getNome(){ return nome; }
main.cpp #include <iostream> #include "pessoa.hpp" #include <string> using namespace std; main(){ Pessoa Objeto; Objeto.setNome("Maria"); cout <<Objeto.getNome(); }
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status make: *** [pessoa] Error 1
/tmp/cc4Iwqt4.o: In function `main': main.cpp:(.text+0x13): undefined reference to `Pessoa::Pessoa()' main.cpp:(.text+0x47): undefined reference to `Pessoa::setNome(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' main.cpp:(.text+0x8d): undefined reference to `Pessoa::getNome()' collect2: ld returned 1 exit status
Enviado em 25/06/2013 - 01:28h
01 - Nos "arquivos.cpp" retirar todas as referencias de #include exceto ( #include pessoa.hpp ).Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
O que você está ouvindo agora? [2] (176)
Erro ao executar o comando para dar um get email (1)