Я пытаюсь внедрить два класса - 'editobject' и 'progressObject'.
progressObject должен наследовать от редакции, все его переменные и методы. Br /> Когда я пытаюсь использовать методы из «editObject» внутри определений «progressObject», однако я получаю ошибку «неопределенной ссылки». < /p>
Вот Коды:
editObject.h
#ifndef EDITOBJECT_H_INCLUDED
#define EDITOBJECT_H_INCLUDED
#include
using namespace std;
class EditObject {
string title;
bool done;
public:
explicit EditObject(const string& _title);
[[nodiscard]] virtual string getTitle() const;
[[nodiscard]] virtual bool isDone() const;
virtual void setDone();
};
#endif //EDITOBJECT_H_INCLUDED
editobject.cpp
#include "EditObject.h"
#include
EditObject::EditObject(const string& _title) : title(_title), done(false) {
if (_title.empty()) throw std::runtime_error("Title cannot be empty");
}
string EditObject::getTitle() const { return title; }
bool EditObject::isDone() const { return done; }
void EditObject::setDone() { done = true; }
progressObject
#ifndef PROGRESSOBJECT_H_INCLUDED
#define PROGRESSOBJECT_H_INCLUDED
#include
#include "EditObject.h"
using namespace std;
class ProgressObject: public EditObject {
protected:
int current;
int max;
public:
explicit ProgressObject(const string& _title,const int& _max);
[[nodiscard]] virtual int getCurrent() const;
[[nodiscard]] virtual int getMax() const;
virtual void add1();
virtual void addn(const int& n);
};
#endif //PROGRESSOBJECT_H_INCLUDED
написанного процесса#include "ProgressObject.h"
#include
#include
using namespace std;
ProgressObject::ProgressObject(const string& _title,const int& _max) : EditObject(_title), current(0), max(_max) {
if (_max max) {
setDone();
current = max;
}
}
main.cpp
#include
#include "Objects/ProgressObject.cpp"
using namespace std;
int main() {
ProgressObject p = ProgressObject("10", 10);
cout
Подробнее здесь: https://stackoverflow.com/questions/794 ... ed-methods
Неопределенная ссылка на наследственные методы [дублировать] ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение