|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2007
Messaggi: 648
|
[C++] Undefined reference su ctor/dtor e metodi
Salve ragazzi,
sto lavorando ad un progettino (allegato in maniera completa infondo) simil-tomboy con pattern observer (ridotto all'osso). Quando vado a compilare mi da un "undefined reference.." Codice:
build/Debug/GNU-Linux-x86/nota.o: In function `Nota': /home/giovanni/NetBeansProjects/tomboy2/nota.cpp:7: undefined reference to `Subject::~Subject()' /home/giovanni/NetBeansProjects/tomboy2/nota.cpp:18: undefined reference to `Subject::~Subject()' build/Debug/GNU-Linux-x86/nota.o: In function `~Nota': /home/giovanni/NetBeansProjects/tomboy2/nota.cpp:23: undefined reference to `Subject::~Subject()' /home/giovanni/NetBeansProjects/tomboy2/nota.cpp:23: undefined reference to `Subject::~Subject()' build/Debug/GNU-Linux-x86/nota.o:(.rodata._ZTV4Nota[vtable for Nota]+0x10): undefined reference to `Nota::registerObserver(Observer*)' build/Debug/GNU-Linux-x86/nota.o:(.rodata._ZTV4Nota[vtable for Nota]+0x14): undefined reference to `Nota::removeObserver(Observer*)' build/Debug/GNU-Linux-x86/nota.o:(.rodata._ZTV4Nota[vtable for Nota]+0x18): undefined reference to `Nota::notifyObservers() const' nota.h Codice:
#ifndef NOTA_H
#define NOTA_H
#include "observer.h"
#include "subject.h"
#include <iostream>
#include <list>
#include <string>
using namespace std;
class Nota : public Subject {
public:
Nota();
Nota(string titolo, string testo);
~Nota();
void stampaTitolo();
void stampaTesto();
void registerObserver( Observer* observer );
void removeObserver( Observer* observer );
void notifyObservers() const;
private:
string _titolo, _testo;
};
#endif
Codice:
#include "nota.h"
#include "observer.h"
#include "subject.h"
#include <iostream>
#include <string>
Nota::Nota(){
string titolo;
string testo;
cout << "Inserisci titolo: " << endl;
getline(cin,titolo);
_titolo = titolo;
cout << "Scrivi il testo della nota: " << endl;
getline(cin,testo);
_testo = testo;
}
Nota::Nota(string titolo, string testo){
_titolo = titolo;
_testo = testo;
}
Nota::~Nota(){
cout << "Nota '" << _titolo << "' cancellata" << endl;
}
void Nota::stampaTitolo(){
cout << _titolo << endl;
}
void Nota::stampaTesto(){
cout << _testo << endl;
}
void Nota::registerObserver(Observer* observer){}
void Nota::removeObserver(Observer* observer){}
void Nota::notifyObservers() const{}
Codice:
#ifndef SUBJECT_H
#define SUBJECT_H
#include "observer.h"
class Subject{
protected:
virtual ~Subject() = 0;
public:
virtual void registerObserver( Observer* observer ) = 0;
virtual void removeObserver( Observer* observer ) = 0;
virtual void notifyObservers() const = 0;
};
#endif
Sapete aiutarmi? grazie ciao |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Oct 2005
Messaggi: 3306
|
Quote:
Il linker si lamenta che non riesce a trovarne una implementazione. I distruttori non possono essere astratti, virtuali si ma una implemerntazione la devono avere! Poi una osservazione: Subject è una interfaccia (definisce tutti metodi astratti), sarebbe meglio che il distruttore fosse pubblico. Infine evita l'utilizzo dello using nei file header. |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:56.




















