inheritance

D

david

Code:
#include <iostream>
#include <cstdarg>
#include <cstdio>
#include <string>
#include <sstream>
#include <exception>
#include "aibe.h"

class DoesNotExistInSet : public std::exception {
public:
DoesNotExistInSet(std::string helpText = "Niekas") :
msg(helpText) {}
~DoesNotExistInSet() throw() {}
virtual const char* what() const throw() {
return msg.c_str();
}
protected:
std::string msg;
};

class AlreadyExistInSet : public DoesNotExitInSet { // 20
public:
AlreadyExistInSet(std::string helpText = "Niekas") :
DoesNotExistInSet(helpText) {} // 22
~AlreadyExistInSet() throw() {}
};

aibe.cpp:20: error: expected class-name before ‘{’ token
aibe.cpp: In constructor
‘AlreadyExistInSet::AlreadyExistInSet(std::string)’:
aibe.cpp:22: error: type ‘class DoesNotExistInSet’ is not a direct
base of ‘AlreadyExistInSet’

Started to learn more about C++ and wanted to create some specific
exception and run into problems.
Any ideas how to fix and why I am getting those errors?
 
R

red floyd

david said:
Code:
#include <iostream>
#include <cstdarg>
#include <cstdio>
#include <string>
#include <sstream>
#include <exception>
#include "aibe.h"

class DoesNotExistInSet : public std::exception {
public:
DoesNotExistInSet(std::string helpText = "Niekas") :
msg(helpText) {}
~DoesNotExistInSet() throw() {}
virtual const char* what() const throw() {
return msg.c_str();
}
protected:
std::string msg;
};

class AlreadyExistInSet : public DoesNotExitInSet { // 20
public:
AlreadyExistInSet(std::string helpText = "Niekas") :
DoesNotExistInSet(helpText) {} // 22
~AlreadyExistInSet() throw() {}
};

aibe.cpp:20: error: expected class-name before ‘{’ token
aibe.cpp: In constructor
‘AlreadyExistInSet::AlreadyExistInSet(std::string)’:
aibe.cpp:22: error: type ‘class DoesNotExistInSet’ is not a direct
base of ‘AlreadyExistInSet’

Started to learn more about C++ and wanted to create some specific
exception and run into problems.
Any ideas how to fix and why I am getting those errors?

Yeah, correct the typo on line 20.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top