Pure Virtual functions
I've got :-
#include <iostream>
#include <string>
#include <new>
using namespace std;
class Message
{
public:
virtual ~Message() {}
virtual Message* clone() const = 0;
virtual string get_type() const = 0;
virtual void set(const string s1, const string s2) = 0;
virtual void print() = 0;
};
class Mail: public Message
{
private:
string m_address;
string m_text;
public:
Mail() {}
Mail(const string addr, const string text) : m_address(addr), m_text(text) {}
virtual Message* clone() const { return new Mail(*this);}
virtual string get_type() const { return "Mail"; }
virtual void set(const string addr, const string text) { m_address = addr; m_text = text; }
virtual void print() const { cout << " * Mail: address = " << m_address << " text = " << m_text << "\n"; }
};
int main()
{
return 0;
}
I'm getting compilation errors :-
-------Configuration: Message - Win32 Debug-------
Compiling...
Message.cpp
C:\C++\Message.cpp(28) : error C2259: 'Mail' : cannot instantiate abstract class due to following members:
C:\C++\Message.cpp(18) : see declaration of 'Mail'
C:\C++\Message.cpp(28) : warning C4259: 'void __thiscall Message::print(void)' : pure virtual function was not defined
C:\C++\Message.cpp(14) : see declaration of 'print'
C:\C++\Message.cpp(28) : error C2259: 'Mail' : cannot instantiate abstract class due to following members:
C:\C++\Message.cpp(18) : see declaration of 'Mail'
C:\C++\Message.cpp(28) : warning C4259: 'void __thiscall Message::print(void)' : pure virtual function was not defined
C:\C++\Message.cpp(14) : see declaration of 'print'
Error executing cl.exe.
Message.obj - 2 error(s), 2 warning(s)
Can someone please help ?
Thanks,
Imanuel.

