-
June 24th, 2009, 07:13 AM
#1
syntax help needed
I want to make Error an abstract class. I want ErrorLog to inherit from Error. What am I doing wrong? How do I fix the code below? Thanks.
#ifndef ERROR_H
#define ERROR_H
#include <QString>
class Error{
public:
Error();
virtual void writeError(QString errorType) const = 0;
};
#endif // ERROR_H
#include "error.h"
Error::Error(){
}
#ifndef ERRORLOG_H
#define ERRORLOG_H
#include "error.h"
class ErrorLog : public Error{
public:
ErrorLog();
virtual void writeError(QString);
};
#endif // ERRORLOG_H
#include "errorlog.h"
#include <QDebug>
ErrorLog::ErrorLog(){
}
void ErrorLog::writeError(QString s){
qDebug()<<"called ErrorLog->writeError()";
}
/***************** main *****************/
#include "errorlog.h"
#include "errorprompt.h"
#include "strategycontext.h"
int main(){
ErrorLog errorlog;
return 0;
}
Errors:
/home/rick/Qt/Error/main.cpp:6: error: cannot declare variable ‘errorlog’ to be of abstract type ‘ErrorLog’
/home/rick/Qt/Error/errorlog.h:5: note: because the following virtual functions are pure within ‘ErrorLog’:
/home/rick/Qt/Error/error.h:9: note: virtual void Error::writeError(QString) const
-
June 24th, 2009, 07:24 AM
#2
Re: syntax help needed
The function signature of ErrorLog::writeError does not match Error::writeError, you´re missing the const modifier.
Code:
class Error
{
virtual void writeError( QString s ) const = 0;
}
class ErrorLog : public Error
{
virtual void writeError( QString s );
}
- Guido
-
June 24th, 2009, 07:52 AM
#3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|