Good Afternoon,

I am from brasil, and i am beginning to study programming, I bought the book "C++ How To Program", and i am now trying to make a small software with each class in its file, with prototypes and etc, here is a simple program that i made to try to fix my problem, here is the code:

File Echoit.h


Echoit.h
#include <string>
using std::string;


class Echoit
{
public:
void setWord(string);
string getWord();
void displayWord();
private:
string typedWord;
};


File Echoit.cpp
___


Echoit.cpp


#include <iostream>
using std::cout;
using std::cin;
using std::endl;


#include "Echoit.h"


#include <string>
using std::string;


Echoit::setWord( string name )
{
typedWord = name;
}


Echoit::getWord()
{
return typedWord;
}


Echoit::displayWord()
{
cout << "A palavra digitada é: " << getWord() << endl;


cout << endl;
}



File main.cpp
__
main.cpp


#include <iostream>
#include "Echoit.h"
#include <string>


using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::getline;


int main()
{
string palavradigitada;
Echoit echoIt1;


cout << "Digite a palavra: " << endl;


getline ( cin, palavradigitada );


echoIt1.setWord( palavradigitada );


echoIt1.displayWord();


return 0;
}

__

When i try to compile this with g++, i get this error:

mudesto@modesto:~/workdir/teste$ g++ main.cpp -o teste
/tmp/ccKD3ike.o: In function `main':
main.cpp:(.text+0xdc): undefined reference to `Echoit::setWord(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
main.cpp:(.text+0x113): undefined reference to `Echoit::displayWord()'
collect2: ld returned 1 exit status

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.