Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 26.03.2013, 00:30   #1
Selean
 
Регистрация: 25.03.2013
Сообщений: 4
По умолчанию Ошибка компиляции

Добрый денью. Прошу мне помочь разобраться.
Учу с++ по книге Дейтел Х., Дейтел П. Как программировать на C++ (5-е издание, 2008)
В книге приводится пример журнала оценок состоящий из трех файлов. Суть урока - разделение реализации программы и интерфейса. По книге нужно компиляция двух исходников GradeBook.cpp и fig03_13.cpp.
Но компилятор ругается:
Если компл-ть файл fig03_13.cpp:
andrew@selean-pc:~/Документы/Книги/C++/exp_cpp/ch03/Fig03_11_13$ g++ fig03_13.cpp
/tmp/ccu1VfOu.o: In function `main':
fig03_13.cpp.text+0x39): undefined reference to `GradeBook::GradeBook(std::string)'
fig03_13.cpp.text+0x85): undefined reference to `GradeBook::GradeBook(std::string)'
fig03_13.cpp.text+0xb0): undefined reference to `GradeBook::getCourseName()'
fig03_13.cpp.text+0xc3): undefined reference to `GradeBook::getCourseName()'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1




Если компл-ть файл GradeBook.cpp:
andrew@selean-pc:~/Документы/Книги/C++/exp_cpp/ch03/Fig03_11_13$ g++ GradeBook.cpp
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
andrew@selean-pc:~/Документы/Книги/C++/exp_cpp/ch03/Fig03_11_13$


Вот вопрос, что не так указано в примерах?


Цитата:

// Fig. 3.11: GradeBook.h
// GradeBook class definition. This file presents GradeBook's public
// interface without revealing the implementations of GradeBook's member
// functions, which are defined in GradeBook.cpp.
#include <string> // class GradeBook uses C++ standard string class
using std::string;

// GradeBook class definition
class GradeBook
{
public:
GradeBook( string ); // constructor that initializes courseName
void setCourseName( string ); // function that sets the course name
string getCourseName(); // function that gets the course name
void displayMessage(); // function that displays a welcome message
private:
string courseName; // course name for this GradeBook
}; // end class GradeBook
--------------------------------------------------------------------------------

// Fig. 3.12: GradeBook.cpp
// GradeBook member-function definitions. This file contains
// implementations of the member functions prototyped in GradeBook.h.
#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h" // include definition of class GradeBook

// constructor initializes courseName with string supplied as argument
GradeBook::GradeBook( string name )
{
setCourseName( name ); // call set function to initialize courseName
} // end GradeBook constructor

// function to set the course name
void GradeBook::setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName

// function to get the course name
string GradeBook::getCourseName()
{
return courseName; // return object's courseName
} // end function getCourseName

// display a welcome message to the GradeBook user
void GradeBook:isplayMessage()
{
// call getCourseName to get the courseName
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
} // end function displayMessage

----------------------------------------------------------------------------------
// Fig. 3.13: fig03_13.cpp
// GradeBook class demonstration after separating
// its interface from its implementation.
#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h" // include definition of class GradeBook

// function main begins program execution
int main()
{
// create two GradeBook objects
GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
GradeBook gradeBook2( "CS102 Data Structures in C++" );

// display initial value of courseName for each GradeBook
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
<< endl;
return 0; // indicate successful termination
} // end main
Selean вне форума Ответить с цитированием
Старый 26.03.2013, 01:53   #2
Ezhik Kihze
Форумчанин
 
Регистрация: 24.12.2012
Сообщений: 639
По умолчанию

Цитата:
Вот вопрос, что не так указано в примерах?
g++ fig03_13.cpp GradeBook.cpp -o myprog
ICQ: 677936656 Gmail: ekEmbed@gmail.com
Ezhik Kihze вне форума Ответить с цитированием
Старый 26.03.2013, 08:18   #3
Selean
 
Регистрация: 25.03.2013
Сообщений: 4
По умолчанию

спасибо. Не догадался.
Selean вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
C++ Ошибка компиляции xays Общие вопросы C/C++ 1 10.02.2012 02:50
C++ ошибка компиляции Seil_29 Помощь студентам 9 20.12.2009 22:23
Ошибка компиляции ImmortalAlexSan C++ Builder 3 20.12.2009 21:19
Ошибка компиляции luk4196 Помощь студентам 4 30.11.2009 23:14
Ошибка компиляции С++ jeka101 Общие вопросы C/C++ 3 27.03.2009 19:16