|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2007
Messaggi: 659
|
[C++] Interfaccia e Linker
Sto seguendo il manuale della Deitel solo che sono ad un punto morto.
Questa è l'interfaccia GradeBook.h Codice:
#include <string>
using namespace std;
class GradeBook{
private:
string courseName;
public:
void setCourseName(string);
string getCourseName();
GradeBook(string);
};
GradeBook.cpp Codice:
#include <iostream>
#include "GradeBook.h"
using namespace std;
void GradeBook::setCourseName(string name)
{
courseName = name;
}
string GradeBook::getCourseName()
{
return courseName;
}
GradeBook::GradeBook(string name)
{
setCourseName(name);
}
TestGradeBook.cpp Codice:
#include <iostream>
#include "GradeBook.h"
using namespace std;
int main()
{
GradeBook gradeBook1("corso 1");
GradeBook gradeBook2("corso 2");
cout << gradeBook1.getCourseName() << "\n" << gradeBook2.getCourseName();
return 0;
}
Codice:
g++ -Wall -o "TestGradeBook" "TestGradeBook.cpp" (nella cartella: /home/andrea/Documenti/C++/GradeBook) /tmp/ccleJ9bv.o: In function `main': TestGradeBook.cpp:(.text+0x45): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' TestGradeBook.cpp:(.text+0x92): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' TestGradeBook.cpp:(.text+0xba): undefined reference to `GradeBook::getCourseName()' TestGradeBook.cpp:(.text+0xcf): undefined reference to `GradeBook::getCourseName()' collect2: ld returned 1 exit status Compilazione fallita. Grazie! Ultima modifica di legolas93 : 05-02-2012 alle 15:25. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
A differenza di altri linguaggi il linker non e' in grado di trovare i file che servono per il collegamento, devi indicarli tutti assieme.
Ad esempio se ad esempio hai compilato i file nel seguente modo Codice:
c++ -c GradeBook.cpp c++ -c TestGradeBook.cpp Codice:
c++ GradeBook.o TestGradeBook.o -o TestGradeBook
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Dec 2007
Messaggi: 659
|
Quote:
PS: cmq il fatto che non venga indicata questa cosa sul Deitel mi sembra una grave mancanza
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:54.



















