CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    3

    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

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: syntax help needed

    The function signature of ErrorLog::writeError does not match Error::writeError, you&#180;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

  3. #3
    Join Date
    Jun 2009
    Posts
    3

    Re: syntax help needed

    Thank you, GNiewerth

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured