Separating Interface from Implementation- Dev-C++ error

I'm reading the book C++ How to Program 5/e by Dietel.
At the Chapter 3.9 'Separating Interface from Implementation' and chapter 3.10 'Validating Data with set Functions' when I try to compile the source codes appears the following:

D:\DOCUME~1\Maloku\LOCALS~1\Temp\ccApbaaa.o(.text+0x1ac) In function `main':
[Linker error] undefined reference to `GradeBook::GradeBook(std::string)'
[Linker error] undefined reference to `GradeBook::GradeBook(std::string)'
[Linker error] undefined reference to `GradeBook::getCourseName()'
[Linker error] undefined reference to `GradeBook::getCourseName()'
[Linker error] undefined reference to `GradeBook::setCourseName(std::string)'
[Linker error] undefined reference to `GradeBook::getCourseName()'
[Linker error] undefined reference to `GradeBook::getCourseName()'
D:\DOCUME~1\Maloku\LOCALS~1\Temp\ccApbaaa.o(.text+0x1ac) ld returned 1 exit status

with DEV-C++.

What can I do to fix that or what causes this problem? I tried microsoft visual c++ 2005 it finds to errors , I'm big beginner

Last edited on
Did you #include "GradeBook.h" in your GradeBook.cpp implementation file?
yes, here the source codes:
------------
//fig03_17
#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h"

int main()
{
GradeBook gradeBook1( "CS101 Introduction to Programming in C++" );
GradeBook gradeBook2( "CS102 C++ Data Structures" );

cout << "gradeBook1's initial course name is: "
<< gradeBook1.getCourseName()
<< "\ngradeBook2's initial course name is: "
<< gradeBook2.getCourseName() << endl;

gradeBook1.setCourseName( "CS101 C++ Programming" );

cout << "\ngradeBook1's course name is: "
<< gradeBook1.getCourseName()
<< "\ngradeBook2's course name is: "
<< gradeBook2.getCourseName() << endl;

return 0;
}
----------------
//gradebook.h
#include <string>
using std::string;

// GradeBook class definition
class GradeBook
{

public:
GradeBook( string );
void setCourseName( string );
string getCourseName();
void displayMessage();

private:
string courseName;
};
-------------------
// Fig. 3.16: GradeBook.cpp
#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h"


GradeBook::GradeBook( string name )
{
setCourseName( name ); // validate and store courseName
}


void GradeBook::setCourseName( string name )
{
if ( name.length() <= 25 )
courseName = name;

if ( name.length() > 25 )
{

courseName = name.substr( 0, 25 ); // start at 0, length of 25

cout << "Name \"" << name << "\" exceeds maximum length (25).\n"
<< "Limiting courseName to first 25 characters.\n" << endl;
}
}

string GradeBook::getCourseName()
{
return courseName; // return object's courseName
}


void GradeBook::displayMessage()
{

cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
}
----------

I click to compile from the first source code fig03_17
It is because main.cpp cannot "see" the implementation details of the class (i.e. the GradeBook.cpp).

The files should be put altogether in a project (something like *.dev) so that things can be linked properly.
THANK YOU FOR ANSWER
It isn't said anything at 'C++ how to program 5/e' that it can't see in fact it should. Do I need to use any other compiler? , i'm new at c++ so when i put them together at *dev how should it look like?
The .cpp cannot "see" each other at compile time, they are compiled into .obj files before they are linked together (by the linker).

Just create an empty console project, save it and add the files, then it would compile everything.
I can't really say how much I want to thank you. You got me to continue with Deitels book where i stopped for long and read C++ for dummies , wich isn't good as Deitels book. Thanks very much
Thanks x Thanks x Thanks128
Topic archived. No new replies allowed.